移除界面所有子视图? 注意区分视图
1. [cell.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
2. for (<#TRRemarkAlertView#> *<#itemAlertView#> in self.<#view.subviews#>) {? //注意view.subviews
? ? if ([<#itemAlertView#> isKindOfClass:[<#TRRemarkAlertView#> class]]) {
? ? ? ? [<#itemAlertView#> removeFromSuperview];
? ? }
}
通知快速设置
1) ? [[NSNotificationCenter defaultCenter] postNotificationName:<#(nonnull NSString *)#> object:nil];? //发送通知对象可改变
[[NSNotificationCenter defaultCenter] postNotificationName:<#(nonnull NSString *)#> object:nil userInfo:@{ <#keyName#> : <#value#> }]; //通知名可以改变
2)
-(void)startMonitorNotification
{
<#[self startMonitorNotification];#>? //要移到别处调用
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(<#selector#>) name:<#(nullable NSString *)#> object:nil];
}
/** 收到<#某某#>页面的通知后做事情,不带userInfo*/
-(void)<#selector#>{
}
3)
-(void)startMonitorNotification{
<#[self startMonitorNotification];#>? //要移到别处调用
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(<#selector:#>) name:<#(nullable NSString *)#> object:nil];
}
/** 收到<#某某#>页面的通知后做事情,带有userInfo */
-(void)<#selector:#>(NSNotification *)note{
}
设置所有的控件都是圆角
-(void)setControlsRoundCorner:(NSArray *)controls{
//[self setControlsRoundCorner:@[<#control1#>,<#control2#>,<#control3#>,<#control4#>]] ;
? ? for (UIView *itemControl in controls) {
? ? ? ? itemControl.layer.borderColor = iosSeperatorLineColor.CGColor ;
? ? ? ? itemControl.layer.borderWidth = 0.5 ;
? ? ? ? itemControl.layer.cornerRadius = 3;
? ? ? ? itemControl.clipsToBounds = YES;
? ? }
}
快速设置CollectionView?
-(void)setupCollectionView
{
CGFloat space = 5 ;
CGFloat column = 2 ; //列数
CGFloat collectionViewX = space? ;
CGFloat collectionViewY = 0;
CGFloat collectionViewW = screen_width - space * 2 ;
CGFloat collectionViewH = screen_height - 64 - 44 - 20 ;
CGRect frame = CGRectMake(collectionViewX,collectionViewY,collectionViewW, collectionViewH) ;
CGFloat InteritemSpacing = space ;
UICollectionViewFlowLayout *collectionViewLayout = [[UICollectionViewFlowLayout alloc] init] ;
collectionViewLayout.minimumInteritemSpacing = space ;
collectionViewLayout.minimumLineSpacing = space ;
//collectionViewLayout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
CGFloat itemWidth = (screen_width - (column -1) * InteritemSpacing - space * 2? )/ column ;
collectionViewLayout.itemSize = CGSizeMake(itemWidth, itemWidth) ;
UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:frame collectionViewLayout:collectionViewLayout] ;
[collectionView registerNib:[UINib nibWithNibName:@"ClassificationCell" bundle:nil] forCellWithReuseIdentifier:@"classificationCell"];
[collectionView registerNib:[UINib nibWithNibName:@"ClassificationReusableView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:reuseIdentifier];
collectionView.dataSource = self ;
collectionView.delegate = self ;
collectionView.backgroundColor =? globalBackColor ;
[self.view addSubview:collectionView];
self.collectionView = collectionView ;
}
图片拉伸(四角不变)
UIImage *image = [UIImage imageNamed:@"11"];
CGFloat top = <#float#>; // 顶端盖高度
CGFloat bottom = <#float#> ; // 底端盖高度
CGFloat left = <#float#>; // 左端盖宽度
CGFloat right = <#float#>; // 右端盖宽度
UIEdgeInsets insets = UIEdgeInsetsMake(top, left, bottom, right);
// 指定为拉伸模式,伸缩后重新赋值
image = [image resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch];
?设置图片拉伸
UIImage *bgImage = [UIImage imageNamed:@""];??
_bgImageView.image = [bgImage stretchableImageWithLeftCapWidth:15 topCapHeight:15];
tableview ?设置
//self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone ;
self.tableView.contentInset = UIEdgeInsetsMake(10, 0, 10, 0) ;
self.tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0) ;
点击事件tapGesture
/** tapGesture代码段 */
-(void)tapGestureClicked{
/**? 此段代码外面调用,给不能添加事件的控件,添加手势
<#viewOrImageView#>.userInteractionEnabled = YES ;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClicked)] ;
tap.numberOfTapsRequired = 1 ;
[<#viewOrImageView#> addGestureRecognizer:tap];
//[tap addTarget:self action:@selector(tapGestureClicked)];
*/
NSLog(@"---------tapClicked--------") ;
}
取消控件的响应
-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent *)event{
? ? NSArray *array =? @[<#item1#>,<#item2#>,<#item3#>] ; //item1,item2,item3等是要辞去第一响应值的控件
? ? NSMutableArray *muArray = [[NSMutableArray alloc] initWithArray:array] ;
? ? for (id item in muArray) {
? ? ? ? if([item isFirstResponder]){
? ? ? ? ? ? [item resignFirstResponder];
? ? ? ? }
? ? }
}
验证所有控件文字非空
/** 验证所有控件文字非空,有一个控件的文字是空就返回yes,没有就返回no */
-(BOOL)validateAllControlsNotNull:(NSArray *)controls :(NSArray *)controlMsgs
{
/** ----此段代码放到外面调用此方法
BOOL result = [self validateAllControllNotNull:@[<#validateControl1#>,<#validateControl2#>,<#validateControl3#>,<#validateControl4#>] :@[@"<#msg#>", @"验证码不能为空"]];
if (result) {? //有一个控件的文字为空就返回
return ;
}else {? //所有的控件的文字都不为空,在此可以进行进一步的验证,比如长度验证,号码验证等
TRLog(@"-----所有的控件的文字都不为空------------") ;
}
*/
for (int i = 0; i < controls.count; i++) {
id itemControl = controls[i] ;
if ([itemControl text].length == 0) {
[self alertViewWithMsg:controlMsgs[i]];
return YES ;
}
}
return NO ;
}
懒加载
-(<#Type#> *)<#Variable#>{
? ? if (!_<#Variable#> ) {
? ? ? ? <#Type#> *<#Variable#>= [[<#Type#> alloc] init];
? ? ? ? self.<#Variable#> = <#Variable#> ;
? ? }
? ? return _<#Variable#> ;
}
?判断输入的是否是纯数字
- (BOOL)isPureInt:(NSString*)string{
? ? NSScanner *scan = [NSScanner scannerWithString:string];
? ? int val;
? ? return [scan scanInt:&val] && [scan isAtEnd];
}
更改UISwitch 控件大小
// 改变 UISwitch? 的大小,CGAffineTransformMakeScale(CGFloat x, CGFloat y) 对 view 的长和宽进行缩放,不改变 view 的中心点
self.orderSwitch.transform =CGAffineTransformMakeScale(0.7,0.7);// 改变 UISwitch 开启时的颜色
self.orderSwitch.onTintColor = KXColorBlue;
别人家整理的,像这位大佬(点进去学习)和这位大佬(点进去学习)整理的很多可用的小块,用处大大的,贴了几个过来,其他的作为学习,对自己进行知识填充,哈哈哈哈哈哈哈哈哈哈哈哈哈哈。。。