ios创建视图的一些方法封装
2015-10-16 13:56
519 查看
<pre class="objc" name="code">//get请求 -(void)getRequestWithString:(NSString *)urlStr andParams:(NSDictionary *)params andAcceptableContentTypes:(NSSet *)acceptableContentTypes { AFHTTPRequestOperationManager *manager=[AFHTTPRequestOperationManager manager]; manager.requestSerializer=[AFJSONRequestSerializer serializer]; manager.responseSerializer.acceptableContentTypes=acceptableContentTypes; [manager GET:urlStr parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) { self.success(responseObject); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"网络请求失败:%@",error); }]; } //post请求 -(void)postRequestWithString:(NSString *)urlStr andParams:(NSDictionary *)params andAcceptableContentTypes:(NSSet *)acceptableContentTypes { AFHTTPRequestOperationManager *manager=[AFHTTPRequestOperationManager manager]; manager.responseSerializer.acceptableContentTypes=acceptableContentTypes; manager.requestSerializer=[AFJSONRequestSerializer serializer]; [manager POST:urlStr parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) { self.success(responseObject); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"网络请求失败:%@",error); }]; } //是否隐藏键盘 -(void)hiddenKeyboard:(BOOL)yesOrNo WithTextfield:(UITextField *)textield { if (yesOrNo==NO) { return; } [textield resignFirstResponder]; NSInteger offset=CGRectGetMaxY(textield.frame)-(HEIGHT-216.0); if (offset>0) { NSTimeInterval animationDuration=0.30f; [UIView beginAnimations:@"ResizeForKeyboard" context:nil]; [UIView setAnimationDuration:animationDuration]; self.view.frame=CGRectMake(0, -offset, WIDTH, HEIGHT); } [UIView commitAnimations]; } //创建按钮 -(UIButton *)createButtonWithButtonType:(UIButtonType)buttonType andFrame:(CGRect)frame andSelecet:(SEL)selector andTitle:(NSString *)title andTitleColor:(UIColor *)titleColor andBackgroundColor:(UIColor *)backgroundColor andNormalImage:(UIImage *)normalIcon andSelectedImage:(UIImage *)selectedIcon { UIButton *btn=[UIButton buttonWithType:buttonType]; btn.frame=frame; [btn setBackgroundColor:backgroundColor]; [btn setTitleColor:titleColor forState:UIControlStateNormal]; [btn setBackgroundImage:normalIcon forState:UIControlStateNormal]; [btn setBackgroundImage:selectedIcon forState:UIControlStateSelected]; [btn addTarget:self action:selector forControlEvents:UIControlEventTouchUpInside]; [btn setTitle:title forState:UIControlStateNormal]; return btn; } //创建label -(UILabel *)createLabelWithFrame:(CGRect)frame andTitle:(NSString *)title andFont:(UIFont *)font andMaskToBounds:(BOOL)maskToBounds { UILabel *label=[[UILabel alloc] initWithFrame:frame]; label.text=title; label.font=font; if (maskToBounds==YES) { label.layer.cornerRadius=5.0; label.layer.masksToBounds=YES; } return label; } //创建textField -(UITextField *)createTextfieldWithFrame:(CGRect)frame andPlaceholder:(NSString *)placeholder andDelegate:(id)delegate { UITextField *textField=[[UITextField alloc] initWithFrame:frame]; textField.placeholder=placeholder; textField.delegate=delegate; return textField; } //创建textView -(UITextView *)createTextViewWithFrame:(CGRect)frame andDelegate:(id)delegate { UITextView *textView=[[UITextView alloc] initWithFrame:frame]; textView.delegate=delegate; return textView; } //创建ImageView -(UIImageView *)createImageViewWithFrame:(CGRect)frame andImage:(UIImage *)icon { UIImageView *iconView=[[UIImageView alloc] initWithFrame:frame]; iconView.image=icon; return iconView; } //创建tableView -(UITableView *)createTableViewWithFrame:(CGRect)frame andDataSource:(id)dataSource andDelegate:(id)delegate { UITableView *tableView=[[UITableView alloc] initWithFrame:frame]; tableView.dataSource=dataSource; tableView.delegate=delegate; return tableView; } //创建scrollView -(UIScrollView *)createScrollViewWithFrame:(CGRect)frame andDelegate:(id)delegate andContentSize:(CGSize)size andShowsHorizontalScrollIndicator:(BOOL)showsHorizontalScrollIndicator andShowsVerticalScrollIndicator:(BOOL)showsVerticalScrollIndicator andPagingEnabled:(BOOL)pagingEnabled { UIScrollView *scrollView=[[UIScrollView alloc] initWithFrame:frame]; scrollView.delegate=delegate; scrollView.contentSize=size; scrollView.showsHorizontalScrollIndicator=showsHorizontalScrollIndicator; scrollView.showsVerticalScrollIndicator=showsVerticalScrollIndicator; scrollView.pagingEnabled=pagingEnabled; return scrollView; }
相关文章推荐
- IOS 代码中修改运营商、电池颜色
- GitHub Top 50 简介 和iOS相关资料总结
- iOS定时器NSTimer
- iOS ---点击图片的方法
- iOS是伪多任务?
- iOS随机数
- iOS categoryde用法以及extension的区别
- GCD学习 dispatch_barrier_async
- Ios学习之popover的使用
- IOS PUSH(ios自学笔记)
- iOS 事件响应链详解(The Responder Chain)
- iOS 3D touch
- xcode中利用iamges.xcassets添加TabbarCtroller中item图标
- iOS之设备型号获取
- iOS对象(字典或数组)转化为JSon字符串
- IOS Post请求与GET请求
- iOS 多线程之GCD使用
- 【iOS】GKPeerPickerController蓝牙设备通讯
- 用CocoaPods做iOS程序的依赖管理
- iOS tintColor解析