【问题标题】:How to make UISegmentedcontrol transparent?如何使 UISegmentedcontrol 透明?
【发布时间】:2014-09-27 10:49:34
【问题描述】:

有人知道如何使UISegmentedControl 透明吗?我设置了ViewController 的背景主题和文本颜色。我目前在ViewDidLoad使用这个代码:

segGame.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.4];

有没有办法以编程方式或在 xib 中设置segmentedControl

【问题讨论】:

    标签: ios objective-c xcode uinavigationcontroller


    【解决方案1】:

    您必须制作自定义段控制器。

    在您的ViewDidLoad 方法中编写此代码。没问题

    请试试这个:

    // Set set segmentControl background to transparent
    
    CGRect rect = CGRectMake(0, 0, 1, 1);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [[UIColor clearColor] CGColor]);
    CGContextFillRect(context, rect);
    UIImage *transparentImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    [segmentControl setBackgroundImage:transparentImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    [segmentControl setDividerImage:transparentImage forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    

    如果你用这个图片,那么它看起来比背景透明度更好

      [segmentControl setDividerImage:[UIImage new] forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
      [segmentControl setBackgroundImage:[UIImage new] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    

    试试这个。

    【讨论】:

    • 有没有办法在xib中设置segmentedControl透明?
    • 点击此链接:framewreck.net/2010/07/…
    • 在 xib 中它已经带有透明的了。你使用的是哪个 xcode?​​span>
    • 我得到了答案,但这仅适用于 IOS 7。我将背景颜色设置为清晰颜色并设置色调颜色 =
    【解决方案2】:

    情节提要非常适合您想要做的事情。看截图。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-17
      • 2011-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多