07選取器總結

來源:互聯網
上載者:User


選取器載入映像時要封裝成UIImageView
UIPickerViewDataSource,UIPickerViewDelegate
 -(NSInteger)numberOfComponentsInPickerView:(UIPickerView* )pickerView;
 -(NSInteger)pickerView:(UIPickerView*)pickerView numberOfRowsInComponent:(NSInteger)component;
 

(required)選取器中的元素
//字串  -(NSString*)pickerView:(UIPickerView*)pickerView
   titleForRow:(NSInteger)row
   forComponent:(NSInteger)component;

//映像    -(UIView*)pickerView:(UIPickerView*)pickerView
   viewForRow:(NSInteger)row
   forComponent:(NSInteger)component;
當選取器有兩個組件(即有兩個框)且右邊框的內容隨左邊框的內容變換而變換時,實現
 -(void)pickerView:(UIPickerView*)pickerView
  didSelectRow:(NSInteger)row
  inComponent:(NSInteger)component;
如果要調整兩個組件的大小則
-(CGFloat)pickerView:(UIPickerView*)pickerView widthForComponent:(NSInteger)component;

注意:IB中需配置pickerView的attribute 中的dataSource與Delegate都連向File's Owner

UIPickerView 方法:-(NSInteger)selectedRowInComponent:(int);
尋找路徑並載入
NSBundle *bundle=[NSBundle mainBundle];
NSString *path=[bundle pathForResource:@"檔案名稱" ofType:@"副檔名"];
NSDictionary *d=[[NSDictionary alloc]initWithContentsOfFile:path];

排序數組
NSArray *array;
NSArray *sorted=[array sortedArrayUsingSelector:@selector(compare:)];

得到字典的全部鍵
NSArray *arr=[dictionary allKeys];

選擇選取器的特定組件特定行並實現動畫
[picker selectedRow:row inComponent:component animated:YES];
[picker reloadComponent:component];

映像匯入
UIImage *image=[UIImage imageName:@"全部檔案名稱"];
UIImageView *imageView=[[UIImageView alloc]initWithName:image];

索引值對
[self setValue:NSObject* forKey:@"..."];

隨機數產生
int i=random()%n;

視頻音頻匯入
#import<AudioToolbox/AudioToobox.h>
第一:記得加入framework
NSString *path=[[NSBundle mainBundle]pathForResource:@"檔案名稱" ofType:@"副檔名"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileWithPath:path],&soundID);
AudioServicesPlaySystemSound(soundID);

自訂調用方法函數
[self performSelector:@selector(函數名) withObject:nil afterDelay:時間];

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.