I am using the following code to create a custom switch:
UISegmentedControl * SwitchView = [[UISegmentedControl alloc] initWithItems: [[NSMutableArray alloc] initWithObjects: @ "On", @ "Off", Zero]]; [Switchview Setframe: CGRKamac (20,365,140,28)]; SwitchView.selectedSegmentIndex = 0; SwitchView.segmentedControlStyle = UISegmentedControlStyleBar; [SwitchViewSet image: [UIImage image named: @ "On sealed"]] session for endex: 0]; [SwitchViewSet image: [UIImage imageNamed: @ "off.png"] SegmentTitindex: 1]; [SwitchWrite Adrase: Action by itself: @Selector (for control events onoffice)): UI ControlEventWalls]; Now I would like to add this control to my screen (I believe the correct word is ViewController?). How do I do it in Xcode 4.3?
I saw some other posts and was not able to find anything that works. For example, some suggestions have been made with the lines of [[myvc view] addSubview: myView] and self.navigationItem.titleView = SwitchView; Recommended, can you also explain why these methods did not work? Thank you.
You have to create a square for your switch that is a subclass of your UISegmentControl, you can either
Add this code to your initWithFrame method
and then use it in your VC
- (zero) viewDidoad {urCustomSwitch = [ UrCustomSwitch alloc] initWithFrame: CGRectMake (20,365,140,28)]; [Self.view addSubview: urCustomSwitch]; } If you want to create a custom reusable class then it will serve your purpose.
Comments
Post a Comment