一 自定义push方法
/* 参数说明
* controllerName : push的目标页 例:@“testcontroll” ---注意不带.h
* isNibPage : 目标页是否带 xib 文件
* setHideTabBar : 当前页是否隐藏 tabBar -----注意 是当前页 非目标页
* setDelegate : 设置委托
*/
- (void)pushNewViewController:(NSString *)controllerName isNibPage:(BOOL) _isNib setHideTabBar:(BOOL) _bool setDelegate:(BOOL) _setdelegate{
if (controllerName.length <= 0) {
return;
}
Class class_Page = NSClassFromString((NSString *)controllerName);
id viewCtrl_Page = _isNib ? [[class_Page alloc] initWithNibName:controllerName bundle:nil]
: [[class_Page alloc] init];
if (_setdelegate) { [viewCtrl_Page setDelegate:self]; }
if (!m_Params) { m_Params = [[NSMutableDictionaryalloc]init]; }
[m_Params setValue:_bool == YES ? @"1" : @"0" forKey:@"HideTabBar"];
[viewCtrl_Page setM_Params:[m_Params retain]];
if (isLoginPage) {
if ([GlobalisUserLogin]) {
[self.navigationControllerpushViewController:viewCtrl_Page animated:YES];
}
else{
[selfshowLoginController];
}
}
else
[self.navigationControllerpushViewController:viewCtrl_Page animated:YES];
[viewCtrl_Page release];
if (m_Params) {
[m_Params release];
}
}
二 根据TableView里的button获取父级UITableViewCell
UIButton *btn_checkBox = (UIButton *)sender;
UITableViewCell * cell = (UITableViewCell *)[btn_checkBox superview];
NSIndexPath* indexPath = [m_tableViewindexPathForCell:cell];
三 常常要算一段文字的长度和高度。下面这段代码可以帮到你
CGSize fontsize = [tmpCoupon.couponDescsizeWithFont:[UIFontboldSystemFontOfSize:13] constrainedToSize:CGSizeMake(162, MAXFLOAT) lineBreakMode:NSLineBreakByWordWrapping];
四 文本编辑的时候键盘档住页面,下面代码自动收缩
- (void)textFieldDidBeginEditing:(UITextField *)textField{
CGRect frame = textField.frame;
int offset = frame.origin.y + 32 - (self.view.frame.size.height - 216.0-10);
NSTimeInterval animationDuration = 0.30f;
[UIView beginAnimations:@"ResizeForKeyBoard" context:nil];
[UIView setAnimationDuration:animationDuration];
float
width = self.view.frame.size.width;
float height =
self.view.frame.size.height;
if(offset > 0){
CGRect rect =
CGRectMake(0.0f, -offset,width,height);
self.view.frame = rect;
}
[UIView commitAnimations];
}
-
(BOOL)textFieldShouldReturn:(UITextField *)textField{
NSTimeInterval
animationDuration = 0.30f;
[UIView beginAnimations:@"ResizeForKeyboard"
context:nil];
[UIView setAnimationDuration:animationDuration];
CGRect rect = CGRectMake(0.0f, 0.0f, self.view.frame.size.width,
self.view.frame.size.height);
self.view.frame = rect;
[UIView
commitAnimations];
[textField resignFirstResponder];
return
YES;
}
// 十六进制设置alpha值
+ (UIColor *)convertHexToRGB:(NSString *)hexString alpha:(CGFloat)alpha {
NSString *str;
if ([hexString hasPrefix:@"0x"] || [hexString hasPrefix:@"0X"]) {
str=[[NSString alloc] initWithFormat:@"%@",hexString];
}else {
str=[[NSString alloc] initWithFormat:@"0x%@",hexString];
}
int rgb;
sscanf([str cStringUsingEncoding:NSUTF8StringEncoding], "%i", &rgb);
[str release];
int red=rgb/(256*256)%256;
int green=rgb/256%256;
int blue=rgb%256;
UIColor *color=[UIColor colorWithRed:red/255.0 green:green/255.0 blue:blue/255.0 alpha:alpha];
return color;
}
原文:http://www.cnblogs.com/yswdarren/p/3554436.html