如何获取 UIAlertController 的框架宽度?
How do I get the frame width of UIAlertController?
我想获取 UIAlertController 框架的宽度,以便我可以指定 UIAlertController 附带的 UIPickerView 和 UIToolbar 的宽度。
我试过使用下面的语句来获取宽度。
alertPicker.view.frame.size.width
但是,宽度和viewController的一样:
self.view.frame.size.width
知道获取 UIAlertController 的宽度吗?非常感谢。
这是我的代码。
UIAlertController *alertPicker = [UIAlertController alertControllerWithTitle:nil message:@"\n\n\n\n\n\n\n\n\n\n\n\n" preferredStyle:UIAlertControllerStyleActionSheet];
CGRect pickerFrame = CGRectMake(8, 0, alertPicker.view.frame.size.width, self.view.frame.size.height/2);
UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame];
pickerView.showsSelectionIndicator = YES;
pickerView.dataSource = self;
pickerView.delegate = self;
UIToolbar* pickerToolbar = [[UIToolbar alloc] initWithFrame: CGRectMake(2, 0, alertPicker.view.frame.size.width, 44)];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStylePlain target:self action:@selector(doneBtnisClicked:)];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
pickerToolbar.items = [[NSArray alloc] initWithObjects:flexSpace,doneBtn,nil];
[alertPicker.view addSubview:pickerToolbar];
[alertPicker.view addSubview:pickerView];
没有直接获取 UIAlertController
宽度的方法。
How to set height and width of a UIAlertController in IOS 8
我想获取 UIAlertController 框架的宽度,以便我可以指定 UIAlertController 附带的 UIPickerView 和 UIToolbar 的宽度。
我试过使用下面的语句来获取宽度。
alertPicker.view.frame.size.width
但是,宽度和viewController的一样:
self.view.frame.size.width
知道获取 UIAlertController 的宽度吗?非常感谢。
这是我的代码。
UIAlertController *alertPicker = [UIAlertController alertControllerWithTitle:nil message:@"\n\n\n\n\n\n\n\n\n\n\n\n" preferredStyle:UIAlertControllerStyleActionSheet];
CGRect pickerFrame = CGRectMake(8, 0, alertPicker.view.frame.size.width, self.view.frame.size.height/2);
UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame];
pickerView.showsSelectionIndicator = YES;
pickerView.dataSource = self;
pickerView.delegate = self;
UIToolbar* pickerToolbar = [[UIToolbar alloc] initWithFrame: CGRectMake(2, 0, alertPicker.view.frame.size.width, 44)];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStylePlain target:self action:@selector(doneBtnisClicked:)];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
pickerToolbar.items = [[NSArray alloc] initWithObjects:flexSpace,doneBtn,nil];
[alertPicker.view addSubview:pickerToolbar];
[alertPicker.view addSubview:pickerView];
没有直接获取 UIAlertController
宽度的方法。
How to set height and width of a UIAlertController in IOS 8