将UIPickerView横放到UIActionSheet中

来源:互联网 发布:jquery.topology.js 编辑:程序博客网 时间:2024/05/17 07:41

如何将UIPickerView调整大小后放入UIActionSheet中,我找了一些资料,成功的实现了,现将代码贴出来。


UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"请选择自动选取号码的个数:\n\n\n\n"
delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"OK" otherButtonTitles:nil];
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;

statesarray = [[NSArray alloc] initWithObjects:@"1", @"2", @"3",@"4", @"5", @"6", @"7",@"8", @"9", @"10",nil];
picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, -40, 100.0, 320.0)];
picker.delegate = self;
picker.showsSelectionIndicator =YES;
//picker.autoresizingMask = UIViewAutoresizingFlexibleWidth;
picker.backgroundColor = [UIColor clearColor];
CGAffineTransform rotate = CGAffineTransformMakeRotation(3.14/2);//调整角度180度,横向。
rotate = CGAffineTransformScale(rotate, 0.10, 2.0);//调整大小
[picker setTransform:rotate];

[actionSheet addSubview:picker];
[picker release];

[actionSheet showInView:self.view]; // show from our table view (pops up in the middle of the table)
[actionSheet release];


#pragma mark -
#pragma mark Picker Data Source Methods
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return [statesarray count];
}
#pragma mark Picker Delegate Methods
/*
 - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
 {
 return [self.statesarray objectAtIndex:row];
 }*/
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
CGRect rect = CGRectMake(0, 0, 160, 160);
UILabel *label = [[[UILabel alloc]initWithFrame:rect] autorelease];
CGAffineTransform rotate = CGAffineTransformMakeRotation(-3.14/2);;//调整角度-180度,横向。
rotate = CGAffineTransformScale(rotate, 0.10, 2.0);;//调整大小
[label setTransform:rotate];
label.text = [statesarray objectAtIndex:row];
label.font = [UIFont systemFontOfSize:68.0];
label.textAlignment = UITextAlignmentCenter;
label.numberOfLines = 0;
label.lineBreakMode = UILineBreakModeWordWrap;
label.backgroundColor = [UIColor clearColor];
label.clipsToBounds = YES;
return label ;
}

原创粉丝点击