gpt4 book ai didi

ios - 如何获取 UIAlertController 的框架宽度?

转载 作者:可可西里 更新时间:2023-11-01 06:13:46 38 4
gpt4 key购买 nike

我想获取 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

关于ios - 如何获取 UIAlertController 的框架宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37409826/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com