I am currently creating it UISegmentedControlprogrammatically as a controller viewDidLoadand adding it to the navigation pane of the view controller, assigning it self.navigationItem.titleView.
UISegmentedControl
viewDidLoad
self.navigationItem.titleView
It's simple enough, but I would like to be able to do this in Interface Builder, and still have not been able to figure out how to do this. Google didn't help either. Can someone describe how to do this in IB or provide an online example? I would be very grateful. Thanks, Howard
If you have the whole stacker in the bar, this is actually quite easy; you can just drag it to the header area and IB will do it right.
Otherwise, you can simply add a segmented control to nib (not necessarily a subview), and then add a view @property IBOutletto it from your controller. Then in viewDidLoad, assign its titleView as usual. Remember to release at dealloc and you are golden.
@property IBOutlet
In IB, you can of course just drag the view into the middle of the navigation controller, and it will work fine if it is inside the same navigation element.
, , - , , . - , , , .
, titleView, , . , , titleView, .
UISegmentedControl, IB, NIB. FileOwner viewcontroller, segmentedControl. viewcontroller segmentedcontrol IBOutlet nib.
, , :
[[NSBundle mainBundle] loadNibNamed:@"TTCustomSegmentedControl" owner:self options:nil]; self.navigationItem.titleView = sortSegmentControl;
Just try (works for me):
UISegmentedControl *mSegmentedControl = [[UISegmentedControl alloc] initWithItems: [NSArray arrayWithObjects: @"Segment 1", @"Segment 2", nil]]; mSegmentedControl.segmentedControlStyle = UISegmentedControlStyleBar; mSegmentedControl.tintColor = [UIColor redColor]; [mSegmentedControl setSelectedSegmentIndex:0]; [mSegmentedControl addTarget:self action:@selector(sectionPress:) forControlEvents:UIControlEventValueChanged]; self.navigationItem.titleView = mSegmentedControl;
You cannot set the property titleViewin IB, but you can create / configure the control as a child of your controller view through Interface Builder, and then in your method viewDidLoad, remove it from your view and set it as titleView:
titleView
[segControl removeFromSuperview]; self.navigationItem.titleView = segControl;
Source: https://habr.com/ru/post/1713005/More articles:Where can I find code samples for XNA using WinForms? - winformsHow to avoid hash (#) char in python? - pythonRedirect does not work after using AjaxContext - ajaxMySQL warning about an unknown column that exists - sqlВопрос о уникальности экземпляра строки в python - pythonEmulate processing with python? - pythonC ++ Starting question: Constructor - c ++Uva 3n + 1 problem - javaSilverlight 3 offline mode - installerNcurses Scrolling Text Reader - ncursesAll Articles