首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >UIActionSheet按钮的颜色

UIActionSheet按钮的颜色
EN

Stack Overflow用户
提问于 2010-11-23 01:40:08
回答 3查看 22K关注 0票数 16

如何更改UIActionSheet按钮的颜色?

EN

回答 3

Stack Overflow用户

发布于 2012-01-13 22:54:24

我已经创建了子类UICustomActionSheet,它允许在UIActionSheet中自定义按钮的字体、颜色和图像。这对于appstore来说是绝对安全的,你可以在下面的链接中找到这个类的代码:

https://github.com/gloomcore/UICustomActionSheet

尽情享受吧!

票数 7
EN

Stack Overflow用户

发布于 2010-11-23 01:45:45

不幸的是,如果不使用未公开的API,就没有正式的方法来更改UIActionSheet上按钮的颜色。如果将UIActionSheet控件派生为子类,则可以对其进行自定义。

请参阅此示例:http://blog.corywiles.com/customizing-uiactionsheet-buttons

票数 1
EN

Stack Overflow用户

发布于 2013-02-07 12:53:03

我们可以使用背景图像来做到这一点。我认为这是最简单的方法。

代码语言:javascript
复制
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Actionsheet" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
        [actionSheet addButtonWithTitle:@"Button 1"]; //Blue color
        [actionSheet addButtonWithTitle:@"Button 2"];
        [actionSheet addButtonWithTitle:@"Cancel"];
        [actionSheet addButtonWithTitle:nil];
        [actionSheet setCancelButtonIndex:2];
        [actionSheet setDestructiveButtonIndex:1];
        [actionSheet showInView:self.view];
        UIButton *button = [[actionSheet subviews] objectAtIndex:1];
        UIImage *img = [button backgroundImageForState:UIControlStateHighlighted];//[UIImage imageNamed:@"alert_button.png"];
        [button setBackgroundImage:img forState:UIControlStateNormal];
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4248400

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档