iOS的UIButton和UILable
来源:互联网 发布:注册域名 编辑:程序博客网 时间:2024/05/16 10:19
初始化UIButton和UILable对象,然后设置按钮的点击事件监听,改变UILable的值为当前时间;
运行截图:
代码如下:
//// ViewController.m// tableviewdemo04//// Created by vrinux on 15/6/4.// Copyright (c) 2015年 vrinux. All rights reserved.//#import "ViewController.h"@interface ViewController ()// 定义按钮;@property (nonatomic,strong) UIButton *mButton;// 定义Label;@property (nonatomic,strong) UILabel *mLable;@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib.// 初始化按钮; _mButton = [UIButton buttonWithType:UIButtonTypeCustom];// 绘制按钮的尺寸; _mButton.frame = CGRectMake(100.0f, 100.0f, 200.0f, 100.0f);// 设置背景颜色; [_mButton setBackgroundColor:[UIColor redColor]];// 设置按钮文字; [_mButton setTitle:@"点击我吧" forState:UIControlStateNormal];// 设置按钮的点击事件,调用函数 onClick: [_mButton addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside];// 将按钮添加到view上面; [self.view addSubview:_mButton];// 初始化UILable; _mLable = [[UILabel alloc] initWithFrame:CGRectMake(100, 350, 200, 100)];// 设置字体大小; _mLable.font = [UIFont boldSystemFontOfSize:18.0f];// 设置字体对齐方式; _mLable.textAlignment = NSTextAlignmentCenter;// 设置文字颜色; _mLable.textColor = [UIColor whiteColor];// 设置背景颜色; [_mLable setBackgroundColor:[UIColor redColor]];// 将按钮添加到view上面; [self.view addSubview:_mLable];}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}// 设置点击事件调用的方法;- (void)onClick:(id)senser{ _mLable.text = [self getDate];}// 获取当前时间;- (NSString *)getDate{ NSDate * senddate=[NSDate date]; NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init]; [dateformatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"]; NSString * locationString=[dateformatter stringFromDate:senddate]; return locationString;}@end
0 0
- iOS的UIButton和UILable
- UILable和UIButton的常用设置
- UILable和UIButton的tittle上面添加下划线
- iOS 之 UILable和UITextFiled的自定义
- Swift学习第六枪-UIButton和UILable
- UILable,UIButton的富文本显示
- iOS 注册或登录页面(UILable,UITextField,UIButton)
- swift基础篇:iOS控件大拌菜:UILable UIButton UITextView
- OC UILable UITextFiled UIButton
- UILable,UIButton字体加粗
- UIWindow UIView UILable UIButton
- UILable &UIImageView& UIButton布局
- iOS UILable标签的使用方法
- UILable 的自使用 iOS
- iOS UILable 根据文字的多少改变UILable的大小
- IOS--UIButton的常用属性和方法
- iOS程序-UIButton和UIImageView的区别
- ios UIButton的图片和文字位置
- Android手机屏幕px转dp和dp转px工具类
- UVa 10118 Free Candies
- poj 3254 状压DP
- Add Two Numbers
- 堆的基本操作:定义、创建、插入、删除、排序
- iOS的UIButton和UILable
- CCNA学习指南 网络互联
- Swift _basics
- nodejs保存文件问题
- Java Exlips 操作 Hadoop
- html引用图片资源无法显示的问题
- [Erlang]时间函数及时间校正机制详解
- Apple Watch视频教程(连载)
- INSERT INTO SELECT 和 SELECT INTO 两种表复制语句