温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2020-06-19 17:17:00 来源:网络 阅读:3059 作者:江山风雨 栏目:移动开发

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

如声音、速度、图片等的大小均可使用该控件操作。今天以图片为例简单讲解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
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI