tag属性:当创建多个同类控件时可以灵活使用。
//通过tag找到相应的tag为26的bnt然后改变其颜色
UIButton *find_bnt = (UIButton *)[self.view viewWithTag:26];
find_bnt.backgroundColor = [UIColor redColor];
UIDatePicker:一些格式和使用
//改变颜色
datePicker.backgroundColor = [UIColor whiteColor];
datePicker.frame = CGRectMake(0, date_Y, self.view.frame.size.width, 150);
//设置语言
NSLocale *locale = [[NSLocale alloc]initWithLocaleIdentifier:@"zh_CN"];
datePicker.locale = locale;
//设置显示格式
datePicker.datePickerMode = UIDatePickerModeDate;
//添加行为
[datePicker addTarget:self action:@selector(datepicker:) forControlEvents:UIControlEventValueChanged];
获取当前时间(NSDate和NSString互转)
//获取当前时间
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"yyyy-MM-dd" ];
NSString *dateTime = [formatter stringFromDate:[NSDate date]];
.h文件
#import<Foundation/Foundation.h>
#import<UIKit/UIKit.h>
@interface WbTool : NSObject
+(NSString *)stringFromDate:(NSDate *)date;
+(NSDate*)dateFromString:(NSString*)string;
@end
.m文件中
#import "WbTool.h"
@implementation WbTool
//NSDate转NSString
+(NSString *)stringFromDate:(NSDate *)date{
//获取系统当前时间
// NSDate* currentDate=[NSDate date];
//用于格式化NSDate对象
NSDateFormatter* dateFormatter=[[NSDateFormatter alloc]init];
//设置格式:zzz表示时区
// [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss zzz"];
[dateFormatter setDateFormat:@" yyyy-MM-dd"];
//NSDate转NSString
NSString* currentDateString=[dateFormatter stringFromDate:date];
//输出currentDateString
NSLog(@"%@",currentDateString);
return currentDateString;
}
//NSString转NSDate
+(NSDate*)dateFromString:(NSString*)string
{
//需要转换的字符串
NSString*dateString= [NSString stringWithFormat:@"%@ 00:00:00",string];
//设置转换格式
NSDateFormatter*formatter=[[NSDateFormatter alloc]init];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
//NSString转NSDate
NSDate*date=[formatter dateFromString:dateString];
return date;
}
@end
UIButton 改变其默认的image和label的位置
bnt.imageEdgeInsets = UIEdgeInsetsMake(0,0,15,bnt.titleLabel.bounds.size.width);
bnt.titleEdgeInsets = UIEdgeInsetsMake(15, bnt.titleLabel.bounds.size.width-67, 0, 0);
//UIEdgeInsetsMake(上,左,下,右);
UIEdgeInsets UIEdgeInsetsMake (
CGFloat top,
CGFloat left,
CGFloat bottom,
CGFloat right
);
UIEdgeInsetsMake
里面的四个参数表示距离上边界、左边界、下边界、右边界的距离,默认都为零。
WebViewJavascriptBridge的使用
后续补上。。。。。。