1、============= 获取UIButton在UITableviewCell的行数
==法1==
cellForRowAtIndexPath
UIButton *btnDelete = [[UIButton alloc] init];
btnDelete.frame = CGRectMake(267, 10, 46, 40);
[btnDelete addTarget:self action:@selector(btnDeleteAction:event:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:btnDelete];
[btnDelete release];
UIButton方法
- (void)btnDeleteAction:(id)sender event:(id)event{
NSSet *touches = [event allTouches];
UITouch *touch = [touches anyObject];
CGPoint currentTouchPosition = [touch locationInView:_tableview];
NSIndexPath *indexPath = [_tableview indexPathForRowAtPoint: currentTouchPosition];
}
==法2==
cellForRowAtIndexPath
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
/**
* other code xxxxxxxxxxx
*/
// Cell creation code here. “theButton” is the button, and “cell” is the cell.
objc_setAssociatedObject(theButton, "cell", cell, OBJC_ASSOCIATION_ASSIGN);
return cell;
}
UIButton方法
- (IBAction)myButtonPressed:(id)sender
{
UITableViewCell *cell = objc_getAssociatedObject(sender, "cell");
if (cell) {
}
}
2、============= UILabel的根据字符串长度自适应大小
NSString *content = @"嘿施主,贫僧真的没有偷瞄你啊,表这样嘛";
UIFont *font = [UIFont systemFontOfSize:15.0];
CGSize size = CGSizeMake(320,2000);
CGSize labelsize = [content sizeWithFont:font constrainedToSize:size lineBreakMode:NSLineBreakByWordWrapping];
UILabel *lbContent = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, labelsize.width, labelsize.height)] autorelease];
lbContent.textColor = [UIColor blackColor];
lbContent.backgroundColor = [UIColor clearColor];
lbContent.numberOfLines = 0;
lbContent.lineBreakMode = NSLineBreakByWordWrapping;
3、============= 导航栏的设置
背景颜色
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
背景图片
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"test.png"] forBarMetrics:UIBarMetricsDefault];
按钮
- (void)edittingButton{
UIButton *leftButton = [[ShareValues shareInstance] setRightBarButton];
[leftButton setTitle:@"编辑" forState:UIControlStateNormal];
[leftButton setTitle:@"编辑" forState:UIControlStateHighlighted];
[leftButton.titleLabel setFont:[UIFont boldSystemFontOfSize:15.0]];
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:leftButton] autorelease];
}
4、============= 获取时间戳
- (NSString *)getTimeStamp{
NSDateFormatter *formater = [[NSDateFormatter alloc] init];
[formater setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
[formater setTimeZone:timeZone];
NSString * curTime = [formater stringFromDate:[NSDate date]];
return curTime;
}
5、============= 监测UITextField内容变化
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldChanged:) name:UITextFieldTextDidChangeNotification object:_tf_VerifyCode];
}
- (void)textFieldChanged:(id)sender
{
if (_tf_VerifyCode.text.length > 0){
_btnGetSubPhone.userInteractionEnabled = YES;
[_btnGetSubPhone setTitleColor:[UIColor colorWithRed:50/255.0 green:79/255.0 blue:133/255.0 alpha:1.0] forState:UIControlStateNormal];
[_btnGetSubPhone setTitleColor:[UIColor colorWithRed:50/255.0 green:79/255.0 blue:133/255.0 alpha:1.0] forState:UIControlStateHighlighted];
}else{
_btnGetSubPhone.userInteractionEnabled = NO;
[_btnGetSubPhone setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
[_btnGetSubPhone setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
}
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self name:UITextFieldTextDidChangeNotification object:nil];
[super dealloc];
}
6、============= 设置圆形UIImageView
UIImageView *imgvReward = [[UIImageView alloc] initWithFrame:CGRectMake(280, 15, 30, 30)];
[imgvReward setBackgroundColor:[UIColor colorWithRed:98/255.0 green:173/255.0 blue:250/255.0 alpha:1.0]];
imgvReward.layer.cornerRadius = imgvReward.frame.size.width / 2;
imgvReward.layer.masksToBounds = YES;