iOS开发4:UIStepper控件的简单使用-成都快上网建站

iOS开发4:UIStepper控件的简单使用

 UIStepper控件类似于UISlider控件,但它有“+”和“-”两个按钮,单击其中一个可使属性value值递增或递减。

创新互联服务热线:028-86922220,为您提供成都网站建设网页设计及定制高端网站建设服务,创新互联网页制作领域十多年,包括成都户外休闲椅等多个方面拥有丰富建站经验,选择创新互联,为企业保驾护航。

如声音、速度、图片等的大小均可使用该控件操作。今天以图片为例简单讲解UIStepper的使用方法。

(1)新建一个Single View Application 项目,全名为“UIStepperTest”。

iOS开发4:UIStepper控件的简单使用 iOS开发4:UIStepper控件的简单使用

 

(2)选择ViewController.xib,修改View的Size属性值为None。

iOS开发4:UIStepper控件的简单使用

(3)在xib中添加一个UIImageView控件和一个UIStepper控件,分别调整其位置和大小并给UIImageView控件添加IBOutlet变量和给UIStepper添加IBOutlet变量和IBAction响应函数。

iOS开发4:UIStepper控件的简单使用 iOS开发4:UIStepper控件的简单使用 iOS开发4:UIStepper控件的简单使用

切换到ViewController.m文件,在

  1. @implementation ViewController 

后添加代码:

  1. @synthesize stepper; 
  2. @synthesize p_w_picpathView; 

(4)选中项目,右击,新建Group,命名为p_w_picpath。向其中添加图片。

iOS开发4:UIStepper控件的简单使用

 

(5)修改

  1. - (void)viewDidLoad 

中的代码如下:

  1. - (void)viewDidLoad 
  2.     [super viewDidLoad]; 
  3.     // Do any additional setup after loading the view, typically from a nib. 
  4.     
  5.     UIImage *im = [UIImage p_w_picpathNamed:@"QQ20130505-2"]; 
  6.     self.p_w_picpathView.p_w_picpath = im; 
  7.     self.stepper.minimumValue = im.size.width/5; 
  8.     self.stepper.maximumValue = im.size.height>im.size.width?im.size.height:im.size.width; 
  9.     self.stepper.stepValue = 20; 
  10.     self.stepper.value = im.size.height; 

 

(6)在UIStepper的响应函数:

  1. - (IBAction)stepperValueChanged:(UIStepper *)sender 

中添加代码如下:

  1. - (IBAction)stepperValueChanged:(UIStepper *)sender { 
  2.      
  3.     int stepValue = sender.value; 
  4.     self.p_w_picpathView.bounds = CGRectMake(self.p_w_picpathView.bounds.origin.x, self.p_w_picpathView.bounds.origin.y, stepValue, stepValue); 

 

 

运行程序,如下:

iOS开发4:UIStepper控件的简单使用iOS开发4:UIStepper控件的简单使用

 

 

 

附件:http://down.51cto.com/data/2362773

网页名称:iOS开发4:UIStepper控件的简单使用
标题URL:http://kswjz.com/article/ieeppj.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流