사용자 정의 pickview 및 선택 효과
5229 단어 view
//
// ViewController.m
// UIPickerViewBySelf
//
// Created by MAC on 13-1-29.
// Copyright (c) 2013 MAC. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize fontlabel;
@synthesize pickView;
- (void)viewDidLoad
{
[super viewDidLoad];
self.pickView.dataSource = self;
self.pickView.delegate = self;
fonts = [UIFont familyNames];
fontSize = [NSArray arrayWithObjects:@"10",@"15",
@"20",@"25",
@"30",@"35",
@"40",@"45", nil];
fontColor =[NSArray arrayWithObjects:
[UIColor redColor],
[UIColor blueColor],
[UIColor blackColor],
[UIColor yellowColor],
[UIColor grayColor],
[UIColor greenColor],
[UIColor brownColor],
[UIColor orangeColor],
[UIColor purpleColor],
[UIColor magentaColor],nil];
for(int i= 0;i<3;i++)
{
int row = 0;
if(i==0)
{
row = [fonts count]/2;
}
else if (i==1)
{
row = [fontColor count]/2;
}
else if (i==2)
{
row =[fontSize count]/2;
}
[pickView selectRow:row inComponent:i animated:true];
}
// [fontColor retain];
// Do any additional setup after loading the view, typically from a nib.
}
-(void) pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
UIView *view0,*view1,*view2;
NSInteger row0,row1,row2;
row0 = [pickView selectedRowInComponent:0];
row1 = [pickView selectedRowInComponent:1];
row2 = [pickView selectedRowInComponent:2];
view0 = [pickView viewForRow:row0 forComponent:0];
view1 = [pickView viewForRow:row1 forComponent:1];
view2 = [pickView viewForRow:row2 forComponent:2];
UILabel *label1,*label2,*label0;
label0 =(UILabel *)[view0 viewWithTag:200];
label1 =(UILabel *)[view1 viewWithTag:200];
label2 =(UILabel *)[view2 viewWithTag:200];
fontlabel.font = [UIFont fontWithName:label0.text size:[label2.text floatValue]];
fontlabel.textColor = label1.backgroundColor;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark -
#pragma mark UIPICKVIEW CUSTOM FUNTION
//
-(NSInteger) numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 3;
}
//
-(NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
if(component==0)
{
return [fonts count];}
else if(component==1)
{
return [fontColor count];
}
else if(component ==2)
{
return [fontSize count];
}
return -1;
}
//
-(CGFloat) pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component
{
if(component==0)
{
return 180.0f;}
else if(component==1)
{
return 90.0f;
}
else if(component ==2)
{
return 50.0f;
}
return 0.0f;
}
// row
-(CGFloat) pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
return 50.0f;
}
// view
-(UIView *) pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
CGFloat width = [self pickerView:pickView widthForComponent:component];
CGFloat rowheight =[self pickerView:pickView rowHeightForComponent:(component)];
UIView *myView = [[UIView alloc]init];
myView.frame =CGRectMake(0.0f, 0.0f, width, rowheight);
UILabel *txtlabel = [[UILabel alloc] init];
txtlabel.tag=200;
txtlabel.frame = myView.frame;
[myView addSubview:txtlabel];
if(component==0)
{
txtlabel.text = [fonts objectAtIndex:row];
}
else if(component==1)
{
txtlabel.backgroundColor =[fontColor objectAtIndex:row];
}
else if(component==2)
{
txtlabel.text =[fontSize objectAtIndex:row];
}
return myView;
}
@end
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Getting Started with Zend Framework 2 - ViewBy default, the action and view in the controller are one-to-one correspondence, such as HellowordController::indexActio...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.