1

The segment control is cant able to relocate the position in vertical.It shows like in the image .Can any one help me to positioning the segment control.

  int offset = BAR_OFFSET + 40 * bars.count;
  for (int i = bars.count; i < guessRows; i++)
  {
   UISegmentedControl *bar = [[UISegmentedControl alloc] initWithItems:
     [NSArray arrayWithObjects:@"", @"", @"", nil]];
   bar.segmentedControlStyle = UISegmentedControlStyleBar;
   bar.transform = CGAffineTransformMakeRotation(M_PI_2);
   bar.momentary = YES;
   [bar addTarget:self action:@selector(submitGuess:)
     forControlEvents:UIControlEventValueChanged];
   CGRect frame = bar.frame;
   frame.origin.y = offset; // position it below the last bar
   frame.origin.x = 20; // give it some padding on the left
   [self.view addSubview:bar]; // add the bar to the main view
   [bars addObject:bar];
   [bar release]; 

 } 

enter image description here

iosdev
  • 277
  • 8
  • 19
  • Please give the code leading to this situation. – rdurand Oct 09 '12 at 08:43
  • @Vladimir question added with code.pls help me to solve – iosdev Oct 09 '12 at 08:48
  • how you need to place the segment Controller ? i mean horizontal or vertical ? @iosdev – Manu Oct 09 '12 at 08:50
  • No i want to change the position of segment controler. @VenkatManohar – iosdev Oct 09 '12 at 08:51
  • once try this bar.frame = CGRectMake(20, 20, 21, 200); @iosdev – Manu Oct 09 '12 at 08:52
  • @iosdev: could you please let me the actual position of your segmentController ? – Manu Oct 09 '12 at 08:55
  • @VenkatManohar i updated the code .Please check – iosdev Oct 09 '12 at 09:01
  • now problem with making the segment control text ..i did the code from this link http://stackoverflow.com/questions/3490358/can-i-show-an-uisegmentedcontrol-object-in-vertical... its not working..i added the segement controll titles as like this `if ([[regions valueForKey:region] boolValue]) { [bar setTitle:[name convertToDisplayName] forSegmentAtIndex:segmentIndex] ; ++segmentIndex; }` how should i proceed for rotating the segement control text.please help me – iosdev Oct 09 '12 at 10:31

2 Answers2

2

you can create segment control programmatic and set frame to maintain your segment control position and add segmentcontrol to your view Controller like this :-

 UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:itemArray];
 segmentedControl.frame = CGRectMake(35, 200, 250, 50);
 segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain;
 segmentedControl.selectedSegmentIndex = 1;

 [self.view addSubview:segmentedControl];
Nitin Gohel
  • 49,482
  • 17
  • 105
  • 144
  • now problem with making the segment control text ..i did the code from this link http://stackoverflow.com/questions/3490358/can-i-show-an-uisegmentedcontrol-object-in-vertical... its not working..i added the segement controll titles as like this `if ([[regions valueForKey:region] boolValue]) { [bar setTitle:[name convertToDisplayName] forSegmentAtIndex:segmentIndex] ; ++segmentIndex; }` how should i proceed for rotating the segement control text.please help me – iosdev Oct 09 '12 at 10:28
  • have you trying like this [segmentedControl setTitle: forSegmentAtIndex:0]; – Nitin Gohel Oct 09 '12 at 10:32
  • then how can i rotate the text in uisegment view controller . – iosdev Oct 09 '12 at 10:36
  • actually i did't get you clearly frnd.. :( Please refure this http://developer.apple.com/library/ios/#documentation/uikit/reference/UISegmentedControl_Class/Reference/UISegmentedControl.html – Nitin Gohel Oct 09 '12 at 10:39
  • i tried to make vertical segment control like this http://stackoverflow.com/questions/9168840/app-store-approval-with-modified-uisegmentedcontrol ,now segment control coming vertically,But i want font in horizontal.Now the font coming in vertical.Can yu please solve – iosdev Oct 09 '12 at 11:01
1

The problem comes from your offset var. At line :

frame.origin.y = offset; // position it below the last bar

Change its value (increase it to lower the position of the view) and try to find the correct value that displays your control correctly.

rdurand
  • 7,342
  • 3
  • 39
  • 72