Thursday, December 29, 2011

Add UIBarButton item into a UIToolBar








UIToolbar *toolbar = [UIToolbar new];
toolbar.barStyle = UIBarStyleBlackTranslucent;
// create a bordered style button with custom title
UIBarButtonItem *facebook = [[[UIBarButtonItem alloc] initWithTitle:@"facebook"
                                 style:UIBarButtonItemStyleBordered   target:self           
                                 action:@selector(fbAction:)] autorelease];

UIBarButtonItem *twitter = [[[UIBarButtonItem alloc] initWithTitle:@"twitter"
                              style:UIBarButtonItemStyleBordered
      target:self
      action:@selector(twAction:)] autorelease];
NSArray *items = [NSArray arrayWithObjects
  facebook,
  twitter,
  nil];
toolbar.items = items;
// size up the toolbar and set its frame
        // please not that it will work only for views without Navigation toolbars. 
[toolbar sizeToFit];
CGFloat toolbarHeight = [toolbar frame].size.height;
CGRect mainViewBounds = self.view.bounds;
[toolbar setFrame:CGRectMake(0,0,320,40)];
[self.view addSubview:toolbar];

Swift Operators - Basic Part 3 (Range operators in swift)

Range Operators: Closed Range operators  Half-Open Range Operators One-Sided Ranges Closed Range Operators:  a...b It defines...