【问题标题】:Extract image of UISegmentedControl on iPhone在 iPhone 上提取 UISegmentedControl 的图像
【发布时间】:2011-12-27 12:03:33
【问题描述】:

我使用UISegmentedControl(只有一个段)作为按钮。但问题是无法更改UISegmentedControl 中的字体大小(在 iOS-5+ 中可能,但我针对的是较低版本的设备)。是否可以从应用程序中提取UISegmentedControl 的图像,以便我可以使用自定义UIButton 将此图像作为背景?

任何帮助将不胜感激。

【问题讨论】:

    标签: iphone ios uisegmentedcontrol image-extraction


    【解决方案1】:

    尝试 UIKit-Artwork-Extractor(在 github.com 上查找)

    【讨论】:

    • 谢谢。它很有用,但不是我想要的。
    【解决方案2】:
    for (UIImageView*imgView in segmentControl.subviews) {
        UIGraphicsBeginImageContext(imgView.frame.size);
        CGContextRef context = UIGraphicsGetCurrentContext();
        [segmentControl.layer renderInContext:context];
        UIImage *yourImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext(); 
    }
    

    并导入 QuartzCore.framework

    【讨论】:

    • 感谢您的回复。此解决方案在模拟器中有效,但在设备上失败并显示错误消息 -[UISegment image]: unrecognized selector sent to instance 0x1b98c0。 (在我的情况下,“thisbutton”是 UIsegmentedControl,段数为 1)。你知道可能是什么原因吗?
    • 但是这个 UIImageView 是你添加的还是标准的? :)
    猜你喜欢
    • 2011-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-20
    • 2011-06-21
    • 1970-01-01
    • 2020-02-08
    • 2014-02-17
    相关资源
    最近更新 更多