3
私はUIAlertControllerフレームの幅を取得したいので、UIAlertControllerに付属するUIPickerViewとUIToolbarの幅を指定することができます。UIAlertControllerのフレーム幅を取得するにはどうすればよいですか?
次の文を使用して幅を取得しようとしました。
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];