在阅读之后,我发现您可以自定义UISwitch控件上的文本和颜色。我很好奇,这些方法是否会导致我的应用程序获得批准并包含在app Store中时出现问题。
取自iPhone Developer's Cookbook Sample Code的示例代码
// Custom font, color
switchView = [[UICustomSwitch alloc] initWithFrame:CGRectZero];
[switchView setCenter:CGPointMake(160.0f,260.0f)];
[switchView setLeftLabelText: @"Foo"];
[switchView setRightLabelText: @"Bar"];
[[switchView rightLabel] setFont:[UIFont fontWithName:@"Georgia" size:16.0f]];
[[switchView leftLabel] setFont:[UIFont fontWithName:@"Georgia" size:16.0f]];
[[switchView leftLabel] setTextColor:[UIColor yellowColor]]; 发布于 2009-03-29 16:21:08
这不会在提交到应用商店时产生问题。只要您不使用任何私有(未记录的)API来构建/更改这些小部件,您就可以使用自定义控件或更改版本的内置控件。
发布于 2010-04-30 09:21:32
您可能会喜欢我实现的自定义开关(开源且免费使用)……它允许设置开关以显示任何文本,或轻松地将其子类化以在曲目中绘制您自己的自定义图像。http://osiris.laya.com/projects/rcswitch/
此开关使绘制图像而不是文本变得容易:继承主开关类并覆盖draw方法,如下所示,您的图像将自动生成动画:
- (void)drawUnderlayersInRect:(CGRect)aRect withOffset:(float)offset inTrackWidth:(float)trackWidth
{
[onImage drawAtPoint:CGPointMake(floorf(aRect.origin.x + 13 + (offset - trackWidth)), floorf((self.bounds.size.height - onImage.size.height) / 2.0))];
[offImage drawAtPoint:CGPointMake(floorf(aRect.origin.x + 15.0 + (offset + trackWidth)), ceilf((self.bounds.size.height - offImage.size.height) / 2.0))];
}发布于 2012-05-08 13:35:00
根本不需要UISwitch子类。我实现的一个相当简单的解决方案是UIView和on touch event在两个图像(开/关)之间切换滑动过渡,仅此而已。
致敬Dhanesh
https://stackoverflow.com/questions/694848
复制相似问题