1

I am adding a series of buttons to my scrollview,So on clicking button I want to highlight that one and deselect remaining all. So every thing Works fine. But i need one more behaviour like if Second button is highlighted I want to show some part of third button so that user knows there is one more category.

float offset=0;


for(int i=0;i<[arrMaincat count];i++)
{

    UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
    btn.tag=i;
    btn.titleLabel.font=[UIFont systemFontOfSize:12];

    btn.titleLabel.lineBreakMode=UILineBreakModeTailTruncation;
    NSString *Categoryname=[[arrMaincat objectAtIndex:i] objectForKey:@"Name"];

    CGSize constraint=CGSizeMake(1000, 30);
    CGSize size1 = [Categoryname sizeWithFont:[UIFont systemFontOfSize:12] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];

        btn.frame=CGRectMake(offset, 0, size1.width, 30);


    [btn setTitle:Categoryname forState:UIControlStateNormal];

    [btn setTitle:Categoryname forState:UIControlStateSelected];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn setTitleColor:UIColorFromRGB(0Xe08043) forState:UIControlStateSelected];

    [btn addTarget:self action:@selector(CategoryChanged:) forControlEvents:UIControlEventTouchUpInside];

    offset=btn.frame.origin.x+btn.frame.size.width+10;

    [self.SliderScroll addSubview:btn];

  }

self.SliderScroll.contentSize=CGSizeMake(offset, SliderScroll.frame.size.height);

Remaning Code http://pastie.org/10277453 Here is my screenshot https://www.dropbox.com/s/xpq9vy39eecab1g/Screen%20Shot%202015-07-07%20at%205.34.15%20pm.png?dl=0 Thank you

siva krishna
  • 1,149
  • 2
  • 15
  • 23

1 Answers1

0

So whats the problem, its a simple calculation of content offset. If the button being highlighted is the last button in the scroll view's current visible frame you can add some hardcoded value (lets say 50) to the content offset.x

Mousam
  • 63
  • 6
  • Im little bit confused how to know highlighted is the last button in the scroll view's current visible frame? – siva krishna Jul 08 '15 at 04:43
  • scroll view's current visible frame can be calculated by content offset + bounds of scroll view while the button position in scroll view can be determined by button's frame – Mousam Jul 09 '15 at 09:56