我的 iOS 6 应用程序中有一个 UISwitch,它的打开和关闭图像是自定义的。
self.testSwitch.onImage = [UIImage imageNamed:@"on"];
self.testSwitch.offImage = [UIImage imageNamed:@"off"];
为此,我使用 77 点宽、22 点高的图像(视网膜中为 154x44),如文档中所述。但我的图像不适合我的 uiswitch,看起来很难看,默认样式隐藏了我的图像,就像所附图像上的那样。
我应该设置什么才能使其正常工作?
Here is 我书上的代码。这并不完全是您想要做的,但它展示了技术并且可以帮助您入门!请注意,我使用的是 79 x 27(不确定您从哪里获得数字):
UIGraphicsBeginImageContextWithOptions(CGSizeMake(79,27), NO, 0);
[[UIColor blackColor] setFill];
UIBezierPath* p = [UIBezierPath bezierPathWithRect:CGRectMake(0,0,79,27)];
[p fill];
NSMutableParagraphStyle* para = [NSMutableParagraphStyle new];
para.alignment = NSTextAlignmentCenter;
NSAttributedString* att =
[[NSAttributedString alloc] initWithString:@"YES" attributes:
@{
NSFontAttributeName:[UIFont fontWithName:@"GillSans-Bold" size:16],
NSForegroundColorAttributeName:[UIColor whiteColor],
NSParagraphStyleAttributeName:para
}];
[att drawInRect:CGRectMake(0,5,79,22)];
UIImage* im = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.sw2.onImage = im;
看起来像这样:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)