[英]Re-create UISwitch
My client doesn't like the gloss on the iOS 5 UISwitch, and wants me to create a non glossy version using some images. 我的客户不喜欢iOS 5 UISwitch上的光泽度,并希望我使用某些图像来创建非光泽度版本。 However I don't know how I would go a bouts this.
但是我不知道该怎么回事。
I have created a UIView Subclass and I don't know what to do next. 我创建了一个UIView子类,但我不知道下一步该怎么做。
Any suggestions as to what I need to do next? 关于下一步我需要做什么?
You can recreate UISwitch
using CoreGraphics (without using images). 您可以使用CoreGraphics(不使用图像)重新创建
UISwitch
。
Have a look at this: DCRoundSwitch 看看这个: DCRoundSwitch
DCRoundSwitch is designed to be a drop in replacement for UISwitch
. DCRoundSwitch旨在替代
UISwitch
。
In any case you should create a UIControl
subclass! 无论如何,您都应该创建一个
UIControl
子类!
There are a number of ways to do what you want. 有很多方法可以做您想要的。 One way is to use a UIImageView and just switch the image when the user taps on the control.
一种方法是使用UIImageView并仅在用户点击控件时切换图像。
Something like: 就像是:
-(void) loadView
{
[super loadView];
UIImageView *image1 = [UIImage imageNamed:@"image1-from-client"];
UIImageView *imageView = [[[UIImageView alloc] initWithImage:image1] autorelease];
imageView.userInteractionEnabled = YES;
[self.view addSubview:imageView];
// detect the tap
UITapGestureRecognizer *tapRecognizer = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)] autorelease];
[imageView addGestureRecognizer:tapRecognizer];
}
// this gets called when the user taps
-(void) tap:(UIGestureRecognizer*)gesture
{
UIImageView *viewTapped = (UIImageView*)gesture.view;
if ( viewTapped.tag == 0 )
{
viewTapped.tag = 1;
viewTapped.image = [UIImage imageNamed:@"image2-from-client"];
}
else
{
viewTapped.tag = 0;
viewTapped.image = [UIImage imageNamed:@"image1-from-client"];
}
}
You can recreate a custom UISwitch
by subclassing UIControl
. 您可以通过子类化
UIControl
来重新创建自定义UISwitch
。 Then you can use regular UIViews to create almost any effect you want. 然后,您可以使用常规的UIView创建几乎所需的任何效果。 You can look take a look at
SevenSwitch
. 您可以看一下
SevenSwitch
。 A custom UISwitch
replacement I've created. 我创建的自定义
UISwitch
替换。 It is non-glossy and the colors can be customized to you're liking. 它不具有光泽,可以根据您的喜好自定义颜色。
https://github.com/bvogelzang/SevenSwitch https://github.com/bvogelzang/SevenSwitch
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.