IOS--设计更丰富的界面

 

   

---完成输入后关闭键盘
在ViewController.h文件中声明,放在属性的下方
- (IBAction)textFiledDoneEditing:(id)sender;
	
切换到ViewController.m,添加代码

- (IBAction)textFiledDoneEditing:(id)sender
	{
		[sender resignFirstResponder];	
	}

----通过触摸背景关闭键盘,  添加一个按钮,让他填充整个屏幕,
用户触到这个按钮就触发操作,将nameFiled和numberFiled设置成第一响应状态
ViewController.h中添加

— (IBAction)backgroundClick:(id)sender;
	
	在实现文件中添加:
		- (IBAction)backgroundClick:(id)sender
			{
				[nameFiled resignFirstResponder];
				[numberFiled resignFirstResponder];	
			}
			

---实现滑块和标签,标签显示滑块的值
在.h 文件中声明一个输出口和一个操作
IBOutlet	UILabel	*sliderLable;

@property (nonatomic, retain) UILable *sliderLable

- (IBAction)sliderChanged:(id)sender;
	
切换到.m文件,添加属性同步    实现sliderChanged:方法
	
@synthesize sliderLable;

- (IBAction)sliderChanged:(id)sender
{
	UISlider *slider = (UISlider *)sender;
	int progressAsInt = (int)(slider.value + 0.5f);
	NSString *newText = [[NSString alloc] initWithFormat:@"%d", 
	progressAsInt];
	sliderLable.text = newText;
	[newText release];
}


----隐藏和显示多个控件的最简单的方法是,
使用UIView作为需要隐藏或显示的项的公共父项.

除了为两个开关创建输出口外,我们还需要为父视图创建输出口

IBOutlet UISwitch	*leftSwitch;
IBOutlet UISwitch *rightswitch;
IBOutlet	UIView	*switchView;

@property (nonatomic, retain) UISwitch *leftSwitch;
@property (nonatomic, retain) UISwitch *rightSwitch;
@property (nonatomic, retain) UIView *switchView;

-(IBAction)switchChanged:(id)sender;
-(IBAction)toggleShowHide:(id)sender;
	
	
在实现文件中添加如下代码
@synthesize leftSwitch;
@synthesize rightSwitch;
@synthesize switchView;

-(IBAction)switchChanged:(id)sender
{
	UISwitch *whichSwich = (UISwitch)sender;
	BOOL setting = whichSwitch.isOn;
	[leftSwitch setOn:setting animated:YES];
	[rightSwitch setOn:setting animated:YES];
}

-(IBAction)toggleShowHide:(id)sender
{
	UISegmentedControl *segmentedControl = (UISegmentedControl *)sender;
	NSInteger segment = segmentedControl.selectedSegmentIndex;
	
	if(segment == 0) [switchView setHidden:ON];
	else [switchView seHidden:YES];
}

  

 

转载于:https://www.cnblogs.com/ShlodenZhang/archive/2013/06/06/3120848.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值