欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

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

程序员文章站 2023-12-19 12:07:58
系统默认的字体是黑色,按钮颜色是蓝色或者红色的,我们怎样自定义字体呢 codeing show uialertcontroller *alertvc = [ui...

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

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弹框的字体颜色及字体的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

上一篇:

下一篇: