【发布时间】:2011-06-13 09:42:56
【问题描述】:
我需要显示一个非全屏视图,并且在其下有一个按钮和 pickerView。 我尝试使用此代码:
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(20,20,200,200)];
container.backgroundColor=[UIColor whiteColor];
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton.frame = CGRectMake(container.frame.origin.x, container.frame.origin.y+5, 170, 20); // position in the parent view and set the size of the button
myButton.titleLabel.textColor=[UIColor redColor];
myButton.titleLabel.text=@"click me";
//myButton.backgroundColor=[UIColor blueColor];
//[myButton backgroundImageForState:<#(UIControlState)#>[UIImage imageNamed:@"iPhone_mainbutton_green.png"];
// add targets and actions
[myButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
// add a buttonview
[container addSubview:myButton];
UIPickerView *piker=[[UIPickerView alloc] initWithFrame:CGRectMake(container.frame.origin.x, container.frame.origin.y +30, 100, 100)];
//piker.numberOfComponents=1;
piker.showsSelectionIndicator=YES;
//piker.delegate=self;
//piker.dataSource=self;
[container addSubview:piker];
[myButton release];
[piker release];
[self.view addSubview:container];
我得到了这个(屏幕上的选择器非常大,不是 100x100):
【问题讨论】:
-
"UIPickerView 不可自定义。完全没有。" stackoverflow.com/questions/901545/uipickerview-customisation
-
但是如果我在 IB 中创建选择器,我可以自定义其大小。
标签: iphone objective-c uipickerview frame