zoukankan      html  css  js  c++  java
  • iphone开发小记

    程序功能:点击Button实现按钮的文本变换

    一,打开Xcode,新建single view based application,拖动一个Button控件到屏幕中间

    项目目录树下包含AppDelegate.h AppDelegate.m MainStoryboard.storyboard ViewController.h ViewController.h等文件
    其中MainStoryboard.storyboard用来设计UI界面,ViewController.*文件用来编码

    ViewController.m代码如下

    #import "ViewController.h"
    
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
    }
    
    - (void)viewDidUnload
    {
        [super viewDidUnload];
        // Release any retained subviews of the main view.
    }
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    }
    
    - (void)dealloc {
        [super dealloc];
    }
    @end

    ViewController.h代码如下

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

    二,通过图形界面实现Button控件的属性(ID)及动作(Action)的配置

    1,鼠标拖动Touch Down事件到ViewController.h文件,xcode会自动提示插入Action

    2,设置Action名称为(OnBtnTouch)

    3,同理,配置按钮的名称(ID),可以在程序中通过这个ID号控制控件

    三,打开ViewController.m文件实现OnBtnTouch的具体逻辑,代码如下:

    ViewController.m代码如下

    #import "ViewController.h"
    
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    @synthesize ibtn;
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
    }
    
    - (void)viewDidUnload
    {
        [self setIbtn:nil];
        [super viewDidUnload];
        // Release any retained subviews of the main view.
    }
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    }
    
    - (void)dealloc {
        [ibtn release];
        [super dealloc];
    }
    - (IBAction)OnBtnTouch:(id)sender {
        [ibtn setTitle:@"Go to Work!" forState:UIControlStateNormal];
    }
    @end

    ViewController.h代码如下

    #import <UIKit/UIKit.h>
    
    @interface ViewController : UIViewController
    
    - (IBAction)OnBtnTouch:(id)sender;
    
    @property (retain, nonatomic) IBOutlet UIButton *ibtn;
    
    @end

    我们只手动添加了下面这行代码,其他都是xcode帮我们自动生成的

    [ibtnsetTitle:@"Go to Work!"forState:UIControlStateNormal];

     

  • 相关阅读:
    http修改443端口,http 强制跳转https
    线程event事件函数实现红绿灯
    信号量设置
    多线程简单实例
    paramiko 实现ssh登录和sftp登录
    在同一台电脑安装python 2 和3,并且怎样安装各自的pip和模块
    ThreadingTCPServer 如何设置端口重用
    Python 变量比较
    python 多线程 并发socket实例
    python 中变量引用问题
  • 原文地址:https://www.cnblogs.com/ciaos/p/3251093.html
Copyright © 2011-2022 走看看