如何更改 Objective C 中 UIPickerView 的宽度

发布于 2024-12-26 00:17:44 字数 556 浏览 0 评论 0原文

如何更改 Objective C 中 UIPickerView 的宽度,我使用以下代码,

    tempFiled = Data;
    [tempFiled resignFirstResponder];
    CGSize sizeOfPopover = CGSizeMake(200, 200);
    CGPoint positionOfPopover = CGPointMake(32, 325);
    [popOverControllerWithPicker presentPopoverFromRect:CGRectMake(positionOfPopover.x, positionOfPopover.y+10, 500, sizeOfPopover.height)
         inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

但是当我尝试更改 CGSize sizeOfPopover = CGSizeMake(200, 200); 中的宽度时它没有改变,我想减小选择器的大小。

how to change the width of the UIPickerView in objective C, I am using the following code,

    tempFiled = Data;
    [tempFiled resignFirstResponder];
    CGSize sizeOfPopover = CGSizeMake(200, 200);
    CGPoint positionOfPopover = CGPointMake(32, 325);
    [popOverControllerWithPicker presentPopoverFromRect:CGRectMake(positionOfPopover.x, positionOfPopover.y+10, 500, sizeOfPopover.height)
         inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

But when i am trying to change the width in CGSize sizeOfPopover = CGSizeMake(200, 200); its not changing, i want to reduce the size of the picker.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱给你人给你 2025-01-02 00:17:44

我遇到了这个问题并以这种方式解决了它:

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    CGRect frame = bpsPicker.frame;
    frame.size.width = 100; // width to be displayed on popover controller
    bpsPicker.frame = frame;

}

使用 ViewDidLoad() 来改变这个值还为时过早。

需要明确的是,viewWillAppear 位于传递给 UIPopover 的 UIViewController 中(此处称为“MyViewController.m”)。因此,

self.myViewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil] ;
self.myViewController.delegate = self;
self.myViewController.contentSizeForViewInPopover = CGSizeMake(320, 360); // or whatever

self.myViewControllerPopover = [[UIPopoverController alloc] initWithContentViewController:self.myViewController] ; 

[self.myViewControllerPopover presentPopoverFromBarButtonItem:self.myToolBarButton permittedArrowDirections:UIPopoverArrowDirectionAny  animated:YES];

I had this problem and solved it this way:

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    CGRect frame = bpsPicker.frame;
    frame.size.width = 100; // width to be displayed on popover controller
    bpsPicker.frame = frame;

}

Using ViewDidLoad() is too early to alter this value.

To be clear the viewWillAppear is in the UIViewController that is passed to the UIPopover (here called 'MyViewController.m').So,

self.myViewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil] ;
self.myViewController.delegate = self;
self.myViewController.contentSizeForViewInPopover = CGSizeMake(320, 360); // or whatever

self.myViewControllerPopover = [[UIPopoverController alloc] initWithContentViewController:self.myViewController] ; 

[self.myViewControllerPopover presentPopoverFromBarButtonItem:self.myToolBarButton permittedArrowDirections:UIPopoverArrowDirectionAny  animated:YES];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文