简体   繁体   English

如何基于其子视图位置移动scrollview(水平)

[英]How To Move scrollview(horizontal) based on In its subview position

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 剩余代码http://pastie.org/10277453这是我的屏幕截图https://www.dropbox.com/s/xpq9vy39eecab1g/Screen%20Shot%202015-07-07%20at%205.34.15%20pm.png?dl = 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 如果突出显示的按钮是滚动视图当前可见框架中的最后一个按钮,则可以向内容偏移量添加一些硬编码值(假设为50)。x

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM