iphone开发之基本UI控件(Button控件,开关控件,分段控件,滑块控件,WebView)

这篇博客主要介绍了iOS开发中的几种基本UI控件,包括Button控件,其拥有Default, Highlighted, Selected和Disabled等多种状态。另外,还提到了Switch控件,类似于Windows的checkbox,具有true和false两种状态。同时,文中也提及了ToolBarView。" 125489933,7565019,JavaScript实现汉字转拼音,"['前端开发', 'JavaScript', '字符串操作']
摘要由CSDN通过智能技术生成

Button控件

iPhone的Button控件可以做的很绚丽,Button可以有多种状态:Default State,Highlighted State,Selected State,Disabled State    

#import <UIKit/UIKit.h>

@interface ButtonsBackgroundViewController : UIViewController {

	UIButton * clearButton;
	UIButton * smallButton;
}

@property (nonatomic, retain) IBOutlet UIButton * clearButton;
@property (nonatomic, retain) IBOutlet UIButton * smallButton;

- (IBAction) disableBut: (id) sender;

@end



#import "ButtonsBackgroundViewController.h"

@implementation ButtonsBackgroundViewController

@synthesize clearButton;
@synthesize smallButton;

- (IBAction) disableBut: (id) sender {
	if(clearButton.enabled == YES) {
		clearButton.enabled = NO;
		smallButton.enabled = NO;
		[((UIButton *) sender) setTitle:@"Enable" forState:UIControlStateNormal];
	}
	else {
		clearButton.enabled = YES;
		smallButton.enabled = YES;
		[((UIButton *) sender) setTitle:@"Disable" forState:UIControlStateNormal];
	}
}

- (void)dealloc {
	[clearButton release];
	[smallButton release];
	[super dealloc];
}

@end

开关控件

开关控件(Switch),有些相windows中的checkbox,它只有两种状态,true和false


#import <UIKit/UIKit.h>

@interface SwitchSliderViewController : UIViewController {
	 UISwitch * mySwitch;
}

@property(nonatomic, retain)IBOutlet UISwitch * mySwitch;

-(IBAction) handleSwitch: (id) sender; 
-(IBAction) handleSlider: (id) sender;

@end

#import "SwitchSliderViewController.h"

@implementation SwitchSliderViewController

@synthesize mySwitch;

- (IBAction) handleSwitch: (id) sender {
	if( [((UISwitch *) sender) isOn] == YES){
		NSLog(@"It's on");
	} else {
		NSLog(@"It's off");
	}
} 

- (IBAction) handleSlider: (id) sender {
	NSLog(@"value: %f", ((UISlider *)sender).value);
	if( [((UISlider *) sender) value] == ((UISlider *) sender) .maximumValue) {
		[mySwitch setOn:YES animated:YES];
	}
}

- (void)dealloc {
	[mySwitch release]; 
	[super dealloc];
} 

@end

分段控件(Segment)

#import <UIKit/UIKit.h>

@interface SegmentViewController : UIViewController {

}

- (IBAction) handleSegment: (id) sender;

@end


#import "SegmentViewController.h"

@implementation SegmentViewController

- (IBAction) handleSegment: (id) sender {
	UISegmentedControl * myseg = (UISegmentedControl *) sender;
	if(myseg.selectedSegmentIndex == 0) {
		NSLog(@"selected zero index...");
	}
	else if(myseg.selectedSegmentIndex == 1) {
		NSLog(@"selected one index...");
	}
	else {
		NSLog(@"selected two index...");
	}
}

- (void)dealloc {
	[super dealloc];
}

@end


ToolBarView

#import <UIKit/UIKit.h>

@interface ToolBarViewController : UIViewController {

	IBOutlet UIActivityIndicatorView * myActivityView;
}

@property (nonatomic, retain) IBOutlet UIActivityIndicatorView * myActivityView;

-(IBAction)onClickStartButton: (id)sender;
-(IBAction)onClickOpenButton: (id)sender;

@end

#import "ToolBarViewController.h"

@implementation ToolBarViewController

@synthesize myActivityView;

-(IBAction)onClickStartButton: (id)sender {
	if ([myActivityView isAnimating]) {
		[myActivityView stopAnimating];			
	} else {
		[myActivityView startAnimating];
	}
}

-(IBAction)onClickOpenButton: (id)sender {
	UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示信息" 
									message:@"您点击了打开按钮" delegate:self 
									cancelButtonTitle:@"Done" 
									otherButtonTitles:nil];
	[alert show];
	[alert release];
}

WebView

#import <UIKit/UIKit.h>

@interface MyWebViewController : UIViewController <UIWebViewDelegate> {
	IBOutlet UITextField * myTextField;
	IBOutlet UIWebView * myWebView;
}

@property(nonatomic, retain) UIWebView * myWebView;
@property(nonatomic, retain) UITextField * myTextField;

- (IBAction) changeLocation: (id) sender;

@end

#import "MyWebViewController.h"

@implementation MyWebViewController

@synthesize myWebView;
@synthesize myTextField;

- (void) viewDidLoad {
	myWebView.delegate = self;
}

- (void)dealloc {
	myWebView.delegate = nil;
	[myTextField release];
	[myWebView release];
	[super dealloc];
}

- (IBAction) changeLocation: (id) sender {
	[myTextField resignFirstResponder];
	NSURL * url = [NSURL URLWithString: myTextField.text];
	NSURLRequest * request = [NSURLRequest requestWithURL:url];
	[myWebView loadRequest:request];
}

#pragma mark WebView 委托
#pragma mark --
- (void)webViewDidFinishLoad: (UIWebView *) webView {
	NSLog(@"%@", [webView stringByEvaluatingJavaScriptFromString:
				  @"document.body.innerHTML"]);
}

@end


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值