UIAlertController的使用-修改按鈕顏色捣郊,添加輸入框

如果選擇的是UIAlertView,想要是使用block回調(diào)選擇的按鈕擒悬,可以使用框架STAlertView
https://github.com/LittleMoster/STAlertView

修改按鈕的文字

 //彈出選擇框模她,詢問用戶是否切換城市
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"是否切換城市?"message:messageStr preferredStyle:UIAlertControllerStyleAlert];
    
    
    //修改按鈕的顏色
    UIAlertAction *sure = [UIAlertAction actionWithTitle:@"切換"style:UIAlertActionStyleDefault handler:^(UIAlertAction *_Nonnull action) {
      //點(diǎn)擊事件的處理
        
    }];
    [sure setValue:[UIColor orangeColor] forKey:@"_titleTextColor"];
    UIAlertAction *cancle = [UIAlertAction actionWithTitle:@"取消"style:UIAlertActionStyleCancel handler:^(UIAlertAction *_Nonnull action) {
        
        
    }];
    [cancle setValue:[UIColor orangeColor] forKey:@"_titleTextColor"];
    [alert addAction:sure];
    [alert addAction:cancle];
    
    [self presentViewController:alert animated:true completion:nil];

帶輸入框的彈出框

#pragma  mark --彈出輸入輸入金額的框
-(void)UIalertViewShow
{
    NSString * messageStr=[NSString stringWithFormat:@"請輸入支付服務(wù)的費(fèi)用"];

   
    UIAlertController *alertCtl = [UIAlertController alertControllerWithTitle:@"金額" message:nil preferredStyle:UIAlertControllerStyleAlert];
    
    [alertCtl addTextFieldWithConfigurationHandler:^(UITextField *textField){
        textField.placeholder = messageStr;
        textField.keyboardType =UIKeyboardTypeNumbersAndPunctuation;
        [textField becomeFirstResponder];
    }];
    
       //修改按鈕的顏色
    UIAlertAction *sure = [UIAlertAction actionWithTitle:@"確定"style:UIAlertActionStyleDefault handler:^(UIAlertAction *_Nonnull action) {
       
        //讀取收入框的內(nèi)容的方法
        UITextField *textF = alertCtl.textFields.firstObject;
        NSLog(@"%@",textF.text);
   
        
    }];
    [sure setValue:MainColor forKey:@"_titleTextColor"];
    UIAlertAction *cancle = [UIAlertAction actionWithTitle:@"取消"style:UIAlertActionStyleCancel handler:^(UIAlertAction *_Nonnull action) {
  
        
    }];
    [cancle setValue:MainColor forKey:@"_titleTextColor"];
    [alertCtl addAction:sure];
    [alertCtl addAction:cancle];
    
    [self presentViewController:alertCtl animated:true completion:nil];
}

簡單的用法

- (id)showAlertWithTitle:(NSString *)title {
    if (iOS8Later) {
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleAlert];
        [alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:alertController animated:YES completion:nil];
        return alertController;
    } else {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title message:nil delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alertView show];
        return alertView;
    }
}

- (void)hideAlertView:(id)alertView {
    if ([alertView isKindOfClass:[UIAlertController class]]) {
        UIAlertController *alertC = alertView;
        [alertC dismissViewControllerAnimated:YES completion:nil];
    } else if ([alertView isKindOfClass:[UIAlertView class]]) {
        UIAlertView *alertV = alertView;
        [alertV dismissWithClickedButtonIndex:0 animated:YES];
    }
    alertView = nil;
}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末懂牧,一起剝皮案震驚了整個(gè)濱河市侈净,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌僧凤,老刑警劉巖畜侦,帶你破解...
    沈念sama閱讀 222,627評論 6 517
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異躯保,居然都是意外死亡旋膳,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 95,180評論 3 399
  • 文/潘曉璐 我一進(jìn)店門途事,熙熙樓的掌柜王于貴愁眉苦臉地迎上來验懊,“玉大人擅羞,你說我怎么就攤上這事∫逋迹” “怎么了减俏?”我有些...
    開封第一講書人閱讀 169,346評論 0 362
  • 文/不壞的土叔 我叫張陵,是天一觀的道長碱工。 經(jīng)常有香客問我娃承,道長,這世上最難降的妖魔是什么怕篷? 我笑而不...
    開封第一講書人閱讀 60,097評論 1 300
  • 正文 為了忘掉前任历筝,我火速辦了婚禮,結(jié)果婚禮上廊谓,老公的妹妹穿的比我還像新娘梳猪。我一直安慰自己,他們只是感情好蹂析,可當(dāng)我...
    茶點(diǎn)故事閱讀 69,100評論 6 398
  • 文/花漫 我一把揭開白布舔示。 她就那樣靜靜地躺著,像睡著了一般电抚。 火紅的嫁衣襯著肌膚如雪惕稻。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 52,696評論 1 312
  • 那天蝙叛,我揣著相機(jī)與錄音俺祠,去河邊找鬼。 笑死借帘,一個(gè)胖子當(dāng)著我的面吹牛蜘渣,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播肺然,決...
    沈念sama閱讀 41,165評論 3 422
  • 文/蒼蘭香墨 我猛地睜開眼蔫缸,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了际起?” 一聲冷哼從身側(cè)響起拾碌,我...
    開封第一講書人閱讀 40,108評論 0 277
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎街望,沒想到半個(gè)月后校翔,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 46,646評論 1 319
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡灾前,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,709評論 3 342
  • 正文 我和宋清朗相戀三年防症,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,861評論 1 353
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡蔫敲,死狀恐怖饲嗽,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情燕偶,我是刑警寧澤喝噪,帶...
    沈念sama閱讀 36,527評論 5 351
  • 正文 年R本政府宣布,位于F島的核電站指么,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏榴鼎。R本人自食惡果不足惜伯诬,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 42,196評論 3 336
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望巫财。 院中可真熱鬧盗似,春花似錦、人聲如沸平项。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,698評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽闽瓢。三九已至接癌,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間扣讼,已是汗流浹背缺猛。 一陣腳步聲響...
    開封第一講書人閱讀 33,804評論 1 274
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留椭符,地道東北人荔燎。 一個(gè)月前我還...
    沈念sama閱讀 49,287評論 3 379
  • 正文 我出身青樓,卻偏偏與公主長得像销钝,于是被迫代替她去往敵國和親有咨。 傳聞我的和親對象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,860評論 2 361

推薦閱讀更多精彩內(nèi)容