UIAlertView addSubview in iOS7

2019-01-01 02:08发布

Adding some controls to UIAlertView was deprecated in iOS7 using addSubview method. As I know Apple promised to add contentView property.

iOS 7 is released now and I see that this property is not added. That is why I search for some custom solution with ability to add progress bar to this alertView. Something for example similar to TSAlertView, but more ready for using in iOS 7.

8条回答
浪荡孟婆
2楼-- · 2019-01-01 02:23

I wrote a full implementation of UIAlertView that mimics the complete UIAlertView API, but adds the contentView property we've all wanted for so long: SDCAlertView.

image

查看更多
千与千寻千般痛.
3楼-- · 2019-01-01 02:24

Here is a project on Github to add any UIView to an UIAlertView-looking dialog on iOS7.

(Copied from this StackOverflow thread.)

Custom iOS7 AlertView dialog

查看更多
泪湿衣
4楼-- · 2019-01-01 02:25

There wont be UIAlertView with custom views in iOS7, nor contentView which Apple changed its mind about, so addSubview is impossible now in UIAlertView.

A good alternative will be SVProgressHUD, according to many threads in Apple's forum.

Edit:

There is officially no addSubview nor subclassing for UIAlertView in iOS7.

The UIAlertView class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified.

Other good alternatives:

ios-custom-alertview by wimagguc

MZFormSheetController.

查看更多
永恒的永恒
5楼-- · 2019-01-01 02:27

For IOS7

UIAlertView *alertView1 = [[UIAlertView alloc] initWithTitle:@"Enter Form Name" 
                                               message:@""
                                               delegate:self 
                                               cancelButtonTitle:@"Cancel"
                                               otherButtonTitles:@"Ok", nil];
alertView1.alertViewStyle = UIAlertViewStyleSecureTextInput;
UITextField *myTextField = [alertView1 textFieldAtIndex:0];
[alertView1 setTag:555];
myTextField.keyboardType=UIKeyboardTypeAlphabet;

[alertView1 show];
查看更多
与风俱净
6楼-- · 2019-01-01 02:29

For those who love simple and effective methods with out having to write lines of code. Here is a cool solution without using any other private frame works for adding subviews to ios 7 alert views,i.e.

[alertView setValue:imageView forKey:@"accessoryView"];

Sample code for better understanding,

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(180, 10, 85, 50)];
UIImage *wonImage = [UIImage imageNamed:@"image.png"];
[imageView setImage:wonImage];

//check if os version is 7 or above
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
      [alertView setValue:imageView forKey:@"accessoryView"];
}else{
      [alertView addSubview:imageView];
}

Hope it helps some one,thanks :)

查看更多
人气声优
7楼-- · 2019-01-01 02:43

You can find simple solution without extra classes here

It is based on setting accessoryView for ordinary UIAlertView.

查看更多
登录 后发表回答