代碼demo已在Github開(kāi)源, MXAlertView, 如果能幫助到您屏积,請(qǐng)幫忙點(diǎn)個(gè)星star哈奕扣,謝謝!
MXAlertView
is an easy popView to use !
效果截圖
選擇按鈕一個(gè) | 選擇按鈕兩個(gè) | 選擇按鈕三個(gè) | 自定義accessoryView |
---|---|---|---|
如何使用
基本用法
- (IBAction)alertTypeOneClicked {
[MXAlertView showWithTopTitle:@"提示" bottomTitles:@[@"關(guān)閉播放"] content:@"你當(dāng)前在4G模式,確定要播放?" dataSource:nil completionHandler:nil];
}
- (IBAction)alertTypeTwoClicked {
[MXAlertView showWithTopTitle:@"提示" bottomTitles:@[@"關(guān)閉播放", @"前去設(shè)置"] content:@"你當(dāng)前在4G模式养葵,確定要播放?" dataSource:nil completionHandler:nil];
}
- (IBAction)alertTypeThreeClicked {
[MXAlertView showWithTopTitle:@"提示" bottomTitles:@[@"關(guān)閉播放", @"繼續(xù)播放", @"前去設(shè)置"] content:@"你當(dāng)前在4G模式瘩缆,確定要播放?" dataSource:nil completionHandler:^(int index, UIButton *sender) {
//selected index is index in the `bottomTitles`
if (index == 0) {
//關(guān)閉播放
} else if (index == 1) {
//繼續(xù)播放
} else {
//前去設(shè)置
}
}];
}
自定義
設(shè)置 dataSource
之后在代理中實(shí)現(xiàn)MXAlertViewDataSource
中的accessoryViewForContentInMXAlertView
- (IBAction)alertTypeFourClicked {
[MXAlertView showWithTopTitle:@"提示" bottomTitles:@[@"關(guān)閉播放", @"前去設(shè)置"] content:@"你當(dāng)前在4G模式佃蚜,確定要播放庸娱?" dataSource:self completionHandler:^(int index, UIButton *sender) {
//selected index is the same index as title in the `bottomTitles`
if (index == 0) {
//關(guān)閉播放
} else if (index == 1) {
//繼續(xù)播放
} else {
//前去設(shè)置
}
}];
}
- (UIView *)accessoryViewForContentInMXAlertView:(MXAlertView *)alertView {
UIView *accessoryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width - 4 * 15, 20)];
UIView *timerImageView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
timerImageView.layer.contents = (__bridge id)[[UIImage imageNamed:@"時(shí)鐘.png"] CGImage];
[accessoryView addSubview:timerImageView];
CGRect timerImageViewFrame = timerImageView.frame;
UILabel *timerLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(timerImageViewFrame) + 2, timerImageViewFrame.origin.y, 50, CGRectGetHeight(timerImageViewFrame))];
timerLabel.font = [UIFont systemFontOfSize:15];
timerLabel.textColor = [UIColor colorWithRed:49/255.0 green:194/255.0 blue:124/255.0 alpha:1.0];
timerLabel.text = @"2:00";
[accessoryView addSubview:timerLabel];
return accessoryView;
}