gpt4 book ai didi

iphone - 横向模式下的 UIPicker 大小调整

转载 作者:行者123 更新时间:2023-12-03 18:32:11 25 4
gpt4 key购买 nike

我正在尝试开发一个具有横向模式 UIPicker 的应用程序,占据(几乎)屏幕的整个宽度(具有 5 或 6 个组件)。你能告诉我如何设置 UIPicker 的大小吗?非常感谢您的帮助。

最佳答案

实际上,我几乎为每个应用程序调整了选择器的大小。我不喜欢它们占据整个屏幕。这是我正在使用的方法:(请注意,我还将选择器旋转为水平)

在viewDidLoad中......

picker = [[UIPickerView alloc] initWithFrame:CGRectZero];
picker.delegate = self;
picker.dataSource = self;
picker.showsSelectionIndicator = NO;


//Resize the picker, rotate it so that it is horizontal and set its position
CGAffineTransform rotate = CGAffineTransformMakeRotation(-1.57);
rotate = CGAffineTransformScale(rotate, .46, 2.25);
CGAffineTransform t0 = CGAffineTransformMakeTranslation(3, 22.5);
picker.transform = CGAffineTransformConcat(rotate,t0);
[self.view addSubview:picker];
[picker release];

然后,我想为我的 View 添加背景图像,以覆盖 UIPicker 的灰色条(现在位于顶部和底部):

//Create the overlay to superimpose ontop of the picker
//In this case, the image is the size of the screen with a transparent area the size of the //UIPickerView cut out in the middle

UIImageView *uiiv = [[UIImageView alloc]
initWithImage:[UIImage imageNamed:@"problem_bg.png"]];
uiiv.userInteractionEnabled = NO;
uiiv.opaque = YES; //for performance
[self.view addSubview:uiiv];
[uiiv release];

UIPickerView委托(delegate)方法:

-(UIView *) pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)rowforComponent:(NSInteger)component reusingView:(UIView *)view
{

UIView *viewForRow = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 280)] autorelease];
UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"myimage.png"]];

img.frame = CGRectMake(0, 0, 102,280);
img.opaque = YES;
[viewForRow addSubview:img];
[img release];
UILabel *label;

UIFont *font = [ UIFont fontWithName:@"Helvetica" size:20];

label = [[[UILabel alloc] initWithFrame:CGRectMake(10, 20, 270, 100)] autorelease];

label.text = @"I am a label";
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor blackColor];
label.font = font;
label.backgroundColor = [UIColor clearColor];
label.opaque = NO;
[viewForRow addSubview:label];

CGAffineTransform rotate = CGAffineTransformMakeRotation(1.57);
[viewForRow setTransform:rotate];
return viewForRow;

}

这提供了一个更小的水平选择器,具有漂亮的外观和感觉。我希望这对某人有帮助。

关于iphone - 横向模式下的 UIPicker 大小调整,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/535164/

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