重新创建 UISwitch

发布于 2024-12-01 12:57:07 字数 137 浏览 2 评论 0原文

我的客户不喜欢 iOS 5 UISwitch 上的光泽,并希望我使用一些图像创建非光泽版本。但我不知道我会如何处理这个问题。

我已经创建了一个 UIView 子类,但我不知道下一步该做什么。

关于我下一步需要做什么有什么建议吗?

My client doesn't like the gloss on the iOS 5 UISwitch, and wants me to create a non glossy version using some images. 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.

Any suggestions as to what I need to do next?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

━╋う一瞬間旳綻放 2024-12-08 12:57:08

您可以使用 CoreGraphics 重新创建 UISwitch(不使用图像)。

看看这个:DCRoundSwitch

DCRoundSwitch 被设计为 UISwitch 的替代品代码>.

无论如何,您应该创建一个 UIControl 子类!

You can recreate UISwitch using CoreGraphics (without using images).

Have a look at this: DCRoundSwitch

DCRoundSwitch is designed to be a drop in replacement for UISwitch.

In any case you should create a UIControl subclass!

月棠 2024-12-08 12:57:08

有很多种方法可以做你想做的事。一种方法是使用 UIImageView 并在用户点击控件时切换图像。

像这样的东西:

-(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"];
  }
}

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.

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"];
  }
}
梦境 2024-12-08 12:57:08

您可以通过子类化 UIControl 来重新创建自定义 UISwitch。然后您可以使用常规 UIView 来创建几乎任何您想要的效果。你可以看看SevenSwitch。我创建的自定义 UISwitch 替代品。它是无光泽的,颜色可以根据您的喜好定制。

https://github.com/bvogelzang/SevenSwitch

You can recreate a custom UISwitch by subclassing UIControl. Then you can use regular UIViews to create almost any effect you want. You can look take a look at SevenSwitch. A custom UISwitch replacement I've created. It is non-glossy and the colors can be customized to you're liking.

https://github.com/bvogelzang/SevenSwitch

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文