首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NSTextAlignmentLeft for UIAlertController

NSTextAlignmentLeft for UIAlertController
EN

Stack Overflow用户
提问于 2015-04-16 05:41:23
回答 1查看 2.8K关注 0票数 5

是否有人能够找到一种方法来设置UIAlertController的文本对齐。更具体地说,行动单的样式?

我使用此方法向操作添加图片(图标):

代码语言:javascript
复制
UIImage *qsimage = [UIImage imageNamed:@"snapshot.png"];
[snapshot setValue:qsimage forKey:@"image"];
//where 'snapshot' is a UIAlertAction

这很好,不用担心,但是当向控制器添加多个操作时,所有的文本都是居中的,但是图像是对齐的,这就创造了一种尴尬的UI体验。

我正试图模仿苹果公司即将推出的音乐应用程序iOS 8.4:

有什么想法?我错过了一些简单的东西吗?

编辑

在进行了一些调试之后,我意识到警报操作在一个UICollectionView中。我可以成功地更改所有按钮的颜色,但不能在对齐方面更改操作的标签。下面是我访问它们的方式:

代码语言:javascript
复制
 [[UICollectionView appearanceWhenContainedIn:[UIAlertController class], nil] setTintColor:[UIColor blueColor]];

我还尝试在带有setTitleTextAttributes对象和键的操作中使用NSDictionary,但没有成功。有什么想法吗?

EN

回答 1

Stack Overflow用户

发布于 2015-07-14 09:05:46

这是经过测试和工作的- UILabel+Appearance.h:

代码语言:javascript
复制
@interface UILabel (FontAppearance)
@property (nonatomic, assign) NSTextAlignment appearanceAlignment UI_APPEARANCE_SELECTOR;
@end


@implementation UILabel (FontAppearance)

-(void)setAppearanceAlignment:(NSTextAlignment)alignment {
    [self setTextAlignment:alignment];
}

-(NSTextAlignment)appearanceAlignment {
    return self.textAlignment;
}

@end

用法:

代码语言:javascript
复制
UILabel * appearanceLabel = [UILabel appearanceWhenContainedIn:UIAlertController.class, nil];
[appearanceLabel setAppearanceAlignment:NSTextAlignmentLeft];
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29666192

复制
相关文章

相似问题

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