第二个iOS应用-显示你的输入

先展示效果:

界面显示

说明:在“Input Your Name”后的输入框中键入字符,轻点“Click it's to Show now!”,“Output Your Name”后以浅灰色显示出“‘输入的内容’is your Name!


设计方法:将Label、Button、Text Field拖入StoryBoard中,排列成如图所示的,然后输入框拖动到@interface的下方(拖动的时候会有一个指向,箭头到代码区的相应位置会出现一道横杠,松开出现一个属性卡,输入名称即可生成相应的@preperty代码,名称务必唯一),输出的那条Label也按上述方法拖入代码区;然后将Button也按上述方法拖入@implerentation中,会生成一个方法,在生成的代码中的{ … }区间写入代码实现:

    self.outputName.text = [NSString stringWithFormat:@"'%@'is your Name!",self.inputName.text];

那么本程序的所有代码如下(其中名称为自己设定的,输入框为inputName,输出框为outputName,按钮为OK):

//
//  HWViewController.m
//  HelloWorld
//
//  Created by Ziwer on 14-3-27.
//  Copyright (c) 2014年 FirstProject. All rights reserved.
//

#import "HWViewController.h"

@interface HWViewController ()
@property (weak, nonatomic) IBOutlet UITextField *inputName;
@property (weak, nonatomic) IBOutlet UILabel *outputName;

@end

@implementation HWViewController
- (IBAction)OK:(id)sender
{
    self.outputName.text = [NSString stringWithFormat:@"'%@'is your Name!",self.inputName.text];
}

@end

.h文件无需改动。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值