黑马程序员---004-第四个UI程序(图片调转)手写代码

<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





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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值