iOS UIButton 如何制作这样漂亮的按钮?

发布于 2024-12-12 07:37:32 字数 158 浏览 2 评论 0原文

这是一个 UIButton 吗?如果是的话,背景红色是怎么做的?显然,它不是 红色 UI 颜色? Xcode 中是否包含相同的工具或实用程序来允许制作按钮 像这样?

在此处输入图像描述

Is this a UIButton? If it is, how is the background red done? Obviously, it is not
red UIColor? Is there same tool or utility included with Xcode to allow making buttons
like this?

enter image description here

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

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

发布评论

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

评论(5

天涯沦落人 2024-12-19 07:37:33

您可以使用私有类UIGlassButton生成类似的按钮。
我首先在这里看到它 http://pastie.org/830884 作者:@schwa。

在 iOS 模拟器中运行使用此代码的应用程序以创建自定义按钮(或在设备中,保存到 $(APP)/Documents 并启用 iTunes 文件共享)。

Class theClass = NSClassFromString(@"UIGlassButton");
UIButton *theButton = [[[theClass alloc] initWithFrame:CGRectMake(10, 10, 120, 44)] autorelease];
// Customize the color
[theButton setValue:[UIColor colorWithHue:0.267 saturation:1.000 brightness:0.667 alpha:1.000] forKey:@"tintColor"];
//[theButton setTitle:@"Accept" forState:UIControlStateNormal];
[self.view addSubview:theButton];

UIGraphicsBeginImageContext(theButton.frame.size);
CGContextRef theContext = UIGraphicsGetCurrentContext();
[theButton.layer renderInContext:theContext];

UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
NSData *theData = UIImagePNGRepresentation(theImage);
[theData writeToFile:@"/Users/<# your user #>/Desktop/button.png" atomically:NO];
UIGraphicsEndImageContext();

获得 png 后,将其用作按钮背景。

或者,您可以以编程方式构建按钮(作者:Jeff Lamarche)。

You can generate similar buttons with private class UIGlassButton.
I saw it first here http://pastie.org/830884 by @schwa.

Run an app with this code in your iOS simulator to create a custom button (or in the device, save to $(APP)/Documents and enable iTunes file sharing).

Class theClass = NSClassFromString(@"UIGlassButton");
UIButton *theButton = [[[theClass alloc] initWithFrame:CGRectMake(10, 10, 120, 44)] autorelease];
// Customize the color
[theButton setValue:[UIColor colorWithHue:0.267 saturation:1.000 brightness:0.667 alpha:1.000] forKey:@"tintColor"];
//[theButton setTitle:@"Accept" forState:UIControlStateNormal];
[self.view addSubview:theButton];

UIGraphicsBeginImageContext(theButton.frame.size);
CGContextRef theContext = UIGraphicsGetCurrentContext();
[theButton.layer renderInContext:theContext];

UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
NSData *theData = UIImagePNGRepresentation(theImage);
[theData writeToFile:@"/Users/<# your user #>/Desktop/button.png" atomically:NO];
UIGraphicsEndImageContext();

Once you obtain the png, use it as button background.

Alternatively, you can build the buttons programmatically (by Jeff Lamarche).

庆幸我还是我 2024-12-19 07:37:33

我编写了几个类来为我编写的计算器生成按钮。这些类根据标准颜色或 RGB 输入 RGB 值生成按钮。这些按钮位于我在 Github 上的 BindleKit 项目中: https://github.com/bindle/BindleKit

回答更改 UIButton 背景color 描述了如何使用这些类以及在哪里可以找到源代码。

要查看按钮的示例,请在 Github 项目中编译 BKCatalog 应用程序或查看屏幕截图 https://github.com/bindle/BindleKit/blob/master/screenshots/BKCatalog-BKButtons.png

I wrote a couple of classes to generate buttons for a calculator I wrote. The classes generate the buttons based upon either standard colors or with RGB input RGB values. The buttons are in my BindleKit project on Github: https://github.com/bindle/BindleKit

My answer to Change UIButton background color describes how to use the classes and where to find the source.

To see examples of the buttons, compile the BKCatalog app in the Github project or look at the screenshot https://github.com/bindle/BindleKit/blob/master/screenshots/BKCatalog-BKButtons.png

花间憩 2024-12-19 07:37:33

您需要为按钮创建背景图像。

然后将图像添加到按钮:

- (void)setImage:(UIImage *)image forState:(UIControlState)state

对于可调整大小的按钮,请参阅:

- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets

您可以使用 Graphics Converter、Photoshop 等程序。

You need to create a background image for the button.

Then add the image to the button:

- (void)setImage:(UIImage *)image forState:(UIControlState)state

Also for resizable buttons see:

- (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets

You can use programs like Graphics Converter, Photoshop and others.

作死小能手 2024-12-19 07:37:33

在 iOS 5 下,你有 UIAppearance。

And under iOS 5, you have UIAppearance.

ぇ气 2024-12-19 07:37:33

您可以使用核心动画层制作一个类似的按钮。

http://www.cimgf。 com/2010/01/28/fun-with-uibuttons-and-core-animation-layers/

You can make a button like that with core animation layers.

http://www.cimgf.com/2010/01/28/fun-with-uibuttons-and-core-animation-layers/

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