[Code Note] iOS-custom selection box (high bottom strength), ios-strength

Source: Internet
Author: User

[Code Note] iOS-custom selection box (high bottom strength), ios-strength

I,

Ii. Code.

ViewController. h

#import <UIKit/UIKit.h>@interface ViewController : UIViewController<UIPickerViewDataSource,UIPickerViewDelegate>@end

 

ViewController. m

# Import "ViewController. h "# define Color (r, g, B, d) [UIColor colorWithRed :( r)/255.0 green :( g)/255.0 blue :( B)/255.0 alpha: d] # define W [UIScreen mainScreen]. bounds. size. width # define H [UIScreen mainScreen]. bounds. size. height @ interface ViewController () {NSMutableArray * arrayData; UIView * chooseView;} @ end @ implementation ViewController-(void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. // initialization selection interface [self addChooseView];} # pragma-mark-functions // initialization selection page-(void) addChooseView {// background box chooseView = [[UIView alloc] initWithFrame: CGRectMake (0, H-H * 0.45, W, H * 0.45)]; chooseView. backgroundColor = Color (230,230,230, 1); [self. view addSubview: chooseView]; // line UIView * line3 = [[UIView alloc] initWithFrame: CGRectMake (0, 0, W, 1)] above the completion button; line3.backgroundColor = Color (202,202,202, 1); [chooseView addSubview: line3]; // line UIView * line4 = [[UIView alloc] initWithFrame: CGRectMake (0, 40, 40, w, 1)]; line4.backgroundColor = Color (202,202,202, 1); [chooseView addSubview: line4]; // complete button UIButton * finishedBtn = [UIButton buttonWithType: Finished]; finishedBtn. frame = CGRectMake (W-50, 5, 50, 30); [finishedBtn setTitleColor: [UIColor blueColor] forState: UIControlStateNormal]; [finishedBtn setTitle: @ "done" forState: UIControlStateNormal]; [Export addTarget: self action: @ selector (optional) forControlEvents: Events]; [chooseView addSubview: Events]; UIPickerView * choosePicker = [[Export alloc] initWithFrame: CGRectMake (0, 40, W, chooseView. bounds. size. height-40)]; choosePicker. delegate = self; choosePicker. dataSource = self; [chooseView addSubview: choosePicker]; arrayData = [[NSMutableArray alloc] initWithObjects: @ "high", @ "medium", @ "strong", @ "weak ", nil] ;}# pragma-mark-doClickActions-(void) doClickFinishButton {chooseView. hidden = YES; NSLog (@ "click Finish") ;}# pragma-mark-UIPickerViewDelegate-(NSInteger) numberOfComponentsInPickerView :( UIPickerView *) pickerView {return 1;}-(NSInteger) pickerView :( UIPickerView *) pickerView numberOfRowsInComponent :( NSInteger) component {return arrayData. count;}-(NSString *) pickerView :( UIPickerView *) pickerView titleForRow :( NSInteger) row forComponent :( NSInteger) component {return [arrayData objectAtIndex: row];}-(void) pickerView :( UIPickerView *) pickerView didSelectRow :( NSInteger) row inComponent :( NSInteger) component {NSString * chooseStr = [NSString stringWithFormat: @ "% ld", (long) row]; NSLog (@ "--- chooseStr -- % @", chooseStr);}-(void) didReceiveMemoryWarning {[super didreceivemorywarning]; // Dispose of any resources that can be recreated .} @ end

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.