【问题标题】:Change the color of button in the center of uiscrollview更改uiscrollview中心按钮的颜色
【发布时间】:2016-09-12 00:48:00
【问题描述】:

我有一个水平的UIScrollView 和 100 UIButton。我想要的是更改滚动视图的center 处的按钮颜色?

【问题讨论】:

  • 问题太宽泛了
  • 你可以根据你UIScrollView的contentOffset知道哪一个是可见的。然后根据您的按钮如何(相同宽度?等),您可以找到“居中”的按钮。我个人建议使用UICollectionViewCell,因为有 100 个按钮,可以重复使用。
  • 这是我的第一个问题,我是新来的,我知道我的问题并不宽泛,但我正在尝试。

标签: ios objective-c uiscrollview uibutton


【解决方案1】:

我使用 LTInfiniteScrollview 从 Github 获取它的代码

-(void)updateView:(UIView *)view withProgress:(CGFloat)progress scrollDirection:(ScrollDirection)direction{


//CATransform3D transform = CATransform3DIdentity;

// scale
// CGFloat size = self.viewSize;
CGPoint center = view.center;
view.center = center;
//size = size * (1.4 - 0.3 * (fabs(progress)));
view.frame = CGRectMake(0, 0, 62 , 62);
view.layer.cornerRadius = 62 / 2;
view.center = center;
if (fabs(progress) <= 0.5)
{

    selectedBtn=(UIButton *)view;
    selectedBtn.backgroundColor=[UIColor orangeColor];
    NSString *title =[NSString stringWithFormat:@"%@",selectedBtn.titleLabel.text];
    [dynamicBtn setTitle:title forState:UIControlStateNormal];
    dynamicBtn.titleLabel.textAlignment=NSTextAlignmentCenter;
    dynamicBtn.titleLabel.numberOfLines=2;
    dynamicBtn.titleLabel.textColor=[UIColor whiteColor];

}

else
{
    selectedBtn=(UIButton *)view;
    //selectedBtn.titleLabel.text=[NSString stringWithFormat:@"%d", (int)view.tag];
    selectedBtn.backgroundColor=COLOR;

    }}

selectedBtn 是滚动视图中心的按钮。 如果有人对 LTInfiniteScrollview 有任何理解问题,可以马上问我。

【讨论】:

    猜你喜欢
    • 2020-08-03
    • 2014-07-11
    • 2016-03-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多