注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

熊猫正正的博客

熊猫正正的天空

 
 
 

日志

 
 

IOS用户界面编程练习  

2013-04-27 00:05:43|  分类: ios开发 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
今天晚上又复习了一遍,用户界面编程的一些基础知识,主要掌握了以下几点:
(1)添加图像视图
(2)关闭键盘,当用户在文本框中输入内容之后
(3)实现开关按钮以及分段控件按钮
(4)实现操作表以及警报
(5)美化按钮,当按钮常态,以及按下时的状态,分别用图形描述

ViewController.h代码:

#import <UIKit/UIKit.h>


@interface ViewController : UIViewController <UIActionSheetDelegate>

@property (weak,nonatomic) IBOutlet UITextField *nameField;

@property (weak,nonatomic) IBOutlet UITextField *numberField;

@property (weak,nonatomic) IBOutlet UILabel *sliderLabel;

@property (weak,nonatomic) IBOutlet UISwitch *leftSwitch;

@property (weak,nonatomic) IBOutlet UISwitch *rightSwitch;

@property (weak,nonatomic) IBOutlet UIButton *doSomethingButton;


- (IBAction)textFieldDoneEditing:(id)sender;

- (IBAction)backgroundTap:(id)sender;

- (IBAction)sliderChanged:(UISlider *)sender;

- (IBAction)switchChanged:(UISwitch *)sender;

- (IBAction)toggleControls: (UISegmentedControl *) sender;

- (IBAction)buttonPressed:(id)sender;


@end



ViewController.m代码:

#import "ViewController.h"


@interface ViewController ()


@end


@implementation ViewController

@synthesize nameField,numberField,sliderLabel,leftSwitch,rightSwitch,doSomethingButton;


- (void)viewDidLoad

{

    [super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

    self.sliderLabel.text = @"50";

    UIImage *buttonImageNormal = [UIImage imageNamed:@"whiteButton.png"];

    UIEdgeInsets insets = UIEdgeInsetsMake(0, 12, 0, 12);

    UIImage *stretchableButtonImageNormal = [buttonImageNormal

                                             resizableImageWithCapInsets:insets];

    [self.doSomethingButton setBackgroundImage:stretchableButtonImageNormal

                                      forState:UIControlStateNormal];

    

    UIImage *buttonImagePressed = [UIImage imageNamed:@"blueButton.png"];

    UIImage *stretchableButtonImagePressed = [buttonImagePressed

                                              resizableImageWithCapInsets:insets];

    [self.doSomethingButton setBackgroundImage:stretchableButtonImagePressed

                                      forState:UIControlStateHighlighted];

}


- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


//单击键盘的return,取消键盘

- (IBAction) textFieldDoneEditing:(id)sender

{

    [sender resignFirstResponder];

}


//单击编辑框之外的地方就取消键盘

- (IBAction) backgroundTap:(id)sender

{

    [self.nameField resignFirstResponder];

    [self.numberField resignFirstResponder];

}


- (IBAction) sliderChanged:(UISlider *)sender

{

    int progress = lroundf(sender.value);

    self.sliderLabel.text = [NSString stringWithFormat:@"%d",progress];

}


- (IBAction) switchChanged:(UISwitch *)sender

{

    BOOL setting = sender.isOn;

    [self.leftSwitch setOn:setting animated:YES];

    [self.rightSwitch setOn: setting animated:YES];

}


- (IBAction) toggleControls:(UISegmentedControl *)sender

{

    if (sender.selectedSegmentIndex == 0)

    {

        self.leftSwitch.hidden = NO;

        self.rightSwitch.hidden = NO;

        self.doSomethingButton.hidden = YES;

    }

    else

    {

        self.leftSwitch.hidden = YES;

        self.rightSwitch.hidden = YES;

        self.doSomethingButton.hidden = NO;

    }

}


- (IBAction)buttonPressed:(id)sender {

    UIActionSheet *actionSheet = [[UIActionSheet alloc]

                                  initWithTitle:@"Are you sure?"

                                  delegate:self

                                  cancelButtonTitle:@"No Way!"

                                  destructiveButtonTitle:@"Yes, I’m Sure!"

                                  otherButtonTitles:nil];

    [actionSheet showInView:self.view];

}


- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex

{

    if (buttonIndex != [actionSheet cancelButtonIndex])

    {

        NSString *msg = nil;

        

        if (self.nameField.text.length > 0)

            msg = [NSString stringWithFormat:@"You can breathe easy,%@,everything went OK.",

                   self.nameField.text];

        else

            msg = @"You can breathe easy,everything went OK.";

        

        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Something was done" message:msg

                                                      delegate:self cancelButtonTitle:@"Phew!" otherButtonTitles:nil, nil];

        [alert show];

    }

}


@end



  评论这张
 
阅读(157)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017