当前位置: 移动技术网 > 移动技术>移动开发>IOS > iOS 修改alertViewController弹框的字体颜色及字体的方法

iOS 修改alertViewController弹框的字体颜色及字体的方法

2019年07月24日  | 移动技术网移动技术  | 我要评论

系统默认的字体是黑色,按钮颜色是蓝色或者红色的,我们怎样自定义字体呢

codeing show

uialertcontroller *alertvc = [uialertcontroller alertcontrollerwithtitle:@"提示" message:@"确认退出登录?" preferredstyle:(uialertcontrollerstylealert)];
 uialertaction *cancelaction = [uialertaction actionwithtitle:@"取消" style:uialertactionstylecancel handler:^(uialertaction * _nonnull action) {
 nslog(@"点击了cancel");
 [alertvc dismissviewcontrolleranimated:yes completion:nil];
 }];
 uialertaction *okaction = [uialertaction actionwithtitle:@"确定" style:uialertactionstyledefault handler:^(uialertaction * _nonnull action) {
 nslog(@"点击了ok");
 [[nsuserdefaults standarduserdefaults] setobject:nil forkey:kloginuserkey];
 [alertvc dismissviewcontrolleranimated:yes completion:nil];
 }];
 //修改title
 nsmutableattributedstring *alertcontrollerstr = [[nsmutableattributedstring alloc] initwithstring:@"提示"];
 [alertcontrollerstr addattribute:nsforegroundcolorattributename value:kmaintextcolor range:nsmakerange(0, 2)];
 [alertcontrollerstr addattribute:nsfontattributename value:[uifont systemfontofsize:15] range:nsmakerange(0, 2)];
 [alertvc setvalue:alertcontrollerstr forkey:@"attributedtitle"];
 //修改message
 nsmutableattributedstring *alertcontrollermessagestr = [[nsmutableattributedstring alloc] initwithstring:@"确认退出登录?"];
 [alertcontrollermessagestr addattribute:nsforegroundcolorattributename value:ksubtextcolor range:nsrangefromstring(@"确认退出登录?")];
 [alertcontrollermessagestr addattribute:nsfontattributename value:[uifont systemfontofsize:13] range:nsrangefromstring(@"确认退出登录?")];
 [alertvc setvalue:alertcontrollermessagestr forkey:@"attributedmessage"];
 //修改按钮字体颜色
 [cancelaction setvalue:kgreencolor forkey:@"titletextcolor"];
 [okaction setvalue:kgreencolor forkey:@"titletextcolor"];
 [alertvc addaction:cancelaction];
 [alertvc addaction:okaction];
 [self presentviewcontroller:alertvc animated:yes completion:nil];

这里的kgreencolor 等是我自定义的颜色,换成自己的字体颜色即可

以上这篇ios 修改alertviewcontroller弹框的字体颜色及字体的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网