<span style="color: rgb(207, 135, 36); line-height: 26px; font-size: 14px; font-family: SimSun;">-----------<a target=_blank target="_blank" href="http://www.itheima.com/" style="color: rgb(202, 0, 0); text-decoration: none;">android</a><a target=_blank target="_blank" href="http://www.itheima.com/" style="color: rgb(202, 0, 0); text-decoration: none;">培训</a><span style="text-indent: 28px;">、</span><a target=_blank target="_blank" href="http://www.itheima.com/" rel="nofollow" style="color: rgb(202, 0, 0); text-decoration: none; text-indent: 28px;">java培训</a><span style="text-indent: 28px;">、java学习型技术博客、期待与您交流!------------</span></span><span style="color: rgb(207, 135, 36); line-height: 26px; font-family: Arial; font-size: 14px;"> </span>
// D_DZViewController.h
// 004-第四个UI程序(图片调转)手写代码
//
// Created by DavidAppleMac on 14-8-15.
// Copyright (c) 2014年 DavidCompany. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface D_DZViewController :UIViewController
@end
//
// D_DZViewController.m
// 004-第四个UI程序(图片调转)手写代码
//
// Created by DavidAppleMac on 14-8-15.
// Copyright (c) 2014年 DavidCompany. All rights reserved.
//
#import "D_DZViewController.h"
@interface D_DZViewController ()
@end
@implementation D_DZViewController
- (void)viewDidLoad
{
// 1.创建按钮
// 1.1 new出一个 UIButton 对象,
UIButton * btnPicture = [[UIButtonalloc] init ] ;
// 1.2 设置图片的大小
btnPicture.frame =CGRectMake(0,0, 100, 100) ;
btnPicture.center =CGPointMake(50,50) ;
// 1.3 设置图片在普通状态下的属性
// 1.3.1 把图片资源名转换为 UIImage对象 ,设置图片在默认状态下的图片
UIImage * imageNomalPicture = [UIImageimageNamed:@"btn_01.png"] ;
[btnPicture setBackgroundImage:imageNomalPictureforState:UIControlStateNormal] ;
// 1.3.2 设置图片标题的内容
[btnPicturesetTitle:@"你点我啊!" forState:UIControlStateNormal] ;
// 1.3.3 设置图片标题的字体
[btnPicture setTitleColor:[UIColorgreenColor] forState:UIControlStateNormal] ;
// 1.4 设置图片在高亮状态下的属性
// 1.4.1 把图片资源名转换为 UIImage 对象 ,设置图片在默认状态下的图片
UIImage * imageHLPicture = [UIImageimageNamed:@"btn_02.png"] ;
[btnPicture setBackgroundImage:imageHLPictureforState:UIControlStateHighlighted] ;
// 1.4.2 设置图片标题的内容
[btnPicture setTitle:@"你点我干啥!" forState:UIControlStateHighlighted] ;
// 1.4.3 设置图片标题的字体
[btnPicture setTitleColor:[UIColorblueColor] forState:UIControlStateHighlighted] ;
// 1.5 监听按钮的点击事件
[btnPicture addTarget:selfaction:@selector(btTest)forControlEvents:UIControlEventTouchUpInside] ;
// 1.6 把图片加载到控制器下的 view 中去
[self.viewaddSubview:btnPicture] ;
// 2.创建文本框
// 2.1 创建文本
UITextField * field1 = [[UITextFieldalloc] init] ;
// 2.2 设置文本的大小
field1.frame =CGRectMake(100,100, 100, 100) ;
// 2.3 设置文本的属性
// 2.3.1 设置文本的背景颜色
[field1 setBackgroundColor:[UIColorredColor]] ;
// 2.3.2 设置文本的中心位置
CGFloat centerX = self.view.frame.size.width *0.5 ;
CGFloat centerY = self.view.frame.size.height *0.5 ;
btnPicture.center =CGPointMake(centerX, centerY) ;
// 2.3.3 设置文本的字体
UIFont * field1Font = [UIFontsystemFontOfSize:12] ;
[field1setFont:field1Font] ;
// 2.4 把文本加载到 view 的的窗口下
[self.viewaddSubview:field1] ;
[superviewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)btTest
{
NSLog(@"chu lai ba @") ;
}
- (void)didReceiveMemoryWarning
{
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end