Wednesday, 15 May 2013

ios - UIAlertController custom font, size, color -



ios - UIAlertController custom font, size, color -

i using new uialertcontroller showing alerts. have code:

// nil titles break alert interface on ios 8.0, we'll using empty strings uialertcontroller *alert = [uialertcontroller alertcontrollerwithtitle: title == nil ? @"": title message: message preferredstyle: uialertcontrollerstylealert]; uialertaction *defaultaction = [uialertaction actionwithtitle: cancelbuttontitle style: uialertactionstylecancel handler: nil]; [alert addaction: defaultaction]; uiviewcontroller *rootviewcontroller = [uiapplication sharedapplication].keywindow.rootviewcontroller; [rootviewcontroller presentviewcontroller:alert animated:yes completion:nil];

now want alter title , message font, color, size , so. what's best way this?

edit: should insert whole code. created category uiview show right alert ios version.

@implementation uiview (alertcompatibility) +( void )showsimplealertwithtitle:( nsstring * )title message:( nsstring * )message cancelbuttontitle:( nsstring * )cancelbuttontitle { float iosversion = [[uidevice currentdevice].systemversion floatvalue]; if (iosversion < 8.0f) { uialertview *alert = [[uialertview alloc] initwithtitle: title message: message delegate: nil cancelbuttontitle: cancelbuttontitle otherbuttontitles: nil]; [alert show]; } else { // nil titles break alert interface on ios 8.0, we'll using empty strings uialertcontroller *alert = [uialertcontroller alertcontrollerwithtitle: title == nil ? @"": title message: message preferredstyle: uialertcontrollerstylealert]; uialertaction *defaultaction = [uialertaction actionwithtitle: cancelbuttontitle style: uialertactionstylecancel handler: nil]; [alert addaction: defaultaction]; uiviewcontroller *rootviewcontroller = [uiapplication sharedapplication].keywindow.rootviewcontroller; [rootviewcontroller presentviewcontroller:alert animated:yes completion:nil]; } }

not sure if against private apis/properties using kvc works me on ios8

uialertcontroller *alertvc = [uialertcontroller alertcontrollerwithtitle:@"dont care goes here, since we're alter below" message:@"" preferredstyle:uialertcontrollerstyleactionsheet]; nsmutableattributedstring *hogan = [[nsmutableattributedstring alloc] initwithstring:@"presenting great... hulk hogan!"]; [hogan addattribute:nsfontattributename value:[uifont systemfontofsize:50.0] range:nsmakerange(24, 11)]; [alertvc setvalue:hogan forkey:@"attributedtitle"]; uialertaction *button = [uialertaction actionwithtitle:@"label text" style:uialertactionstyledefault handler:^(uialertaction *action){ //add code create happen 1 time tapped }]; uiimage *accessoryimage = [uiimage imagenamed:@"someimage"]; [button setvalue:accessoryimage forkey:@"image"];

ios objective-c ios8 uialertview uialertcontroller

No comments:

Post a Comment