- 可以批量修改光標(biāo)所在位置的變量 control + command + e
- 界面左側(cè)的項(xiàng)目導(dǎo)航欄中顯示當(dāng)前文件command + shift + j
- UITextField系統(tǒng)自帶邊框
//設(shè)置邊框樣式
//UITextBorderStyleRoundedRect-圓角矩形项郊,背景是白色,不再是透明的
//UITextBorderStyleLine-矩形,黑色邊框庇谆,透明背景
//UITextBorderStyleBezel-和上面類似,但是是灰色的邊框,背景透明
textFiled.borderStyle=UITextBorderStyleRoundedRect;
- UITextView設(shè)置placeholder
KVC鍵值編碼枫慷,對(duì)UITextView的私有屬性進(jìn)行修改(系統(tǒng)版本8.3以上)
UILabel *placeholderLabel = [[UILabel alloc]init];
placeholderLabel.text = @"請(qǐng)輸入內(nèi)容";
placeholderLabel.textColor = [UIColor colorWithRed:153/255.0 green:153/255.0 blue:153/255.0 alpha:1];
[textView addSubview:placeholderLabel];
[textView setValue:placeholderLabel forKeyPath:@"placeholderLabel"];
- 修改UISearBar內(nèi)部背景,placeholder顏色
KVC鍵值編碼
UITextField * searchField = [_searchBar valueForKey:@"_searchField"];
textField.backgroundColor = [UIColor redColor];
[searchField setValue:[UIColor lightGrayColor] forKeyPath:@"_placeholderLabel.textColor"];
[searchField setValue:[UIFont boldSystemFontOfSize:12]forKeyPath:@"_placeholderLabel.font"];
6.是否包含字符串(不區(qū)分大小寫)
localizedCaseInsensitiveContainsString
- UIView設(shè)置部分圓角
CGRect rect = view.bounds;
CGSize radio = CGSizeMake(30, 30);//圓角尺寸
UIRectCorner corner = UIRectCornerTopLeft|UIRectCornerTopRight;//這只圓角位置
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:corner cornerRadii:radio];
CAShapeLayer *masklayer = [[CAShapeLayer alloc]init];//創(chuàng)建shapelayer
masklayer.frame = view.bounds;
masklayer.path = path.CGPath;//設(shè)置路徑
view.layer.mask = masklayer;
- dispatch_semaphore信號(hào)量
//創(chuàng)建信號(hào)量浪规,參數(shù):信號(hào)量的初值或听,如果小于0則會(huì)返回NULL
dispatch_semaphore_create(信號(hào)量值)
//等待降低信號(hào)量
dispatch_semaphore_wait(信號(hào)量,等待時(shí)間)
//提高信號(hào)量
dispatch_semaphore_signal(信號(hào)量)
dispatch_queue_t workConcurrentQueue = dispatch_queue_create("cccccccc", DISPATCH_QUEUE_CONCURRENT);
dispatch_queue_t serialQueue = dispatch_queue_create("sssssssss",DISPATCH_QUEUE_SERIAL);
dispatch_semaphore_t semaphore = dispatch_semaphore_create(2);
for (NSInteger i = 0; i < 10; i++) {
dispatch_async(serialQueue, ^{
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
dispatch_async(workConcurrentQueue, ^{
NSLog(@"thread-info:%@開始執(zhí)行任務(wù)%d",[NSThread currentThread],(int)i);
sleep(1);
NSLog(@"thread-info:%@結(jié)束執(zhí)行任務(wù)%d",[NSThread currentThread],(int)i);
dispatch_semaphore_signal(semaphore);
});
});
}
NSLog(@"主線程...!");
- objc_property_t反射
//objc_property_t:表示類對(duì)象中的全局屬性笋婿,即用@property定義的屬性
//動(dòng)態(tài)獲取一個(gè)自定義類對(duì)象中的所有屬性
- (NSDictionary *)allProperties
{
NSMutableDictionary *props = [NSMutableDictionary dictionary];
unsigned int outCount, i;
objc_property_t *properties = class_copyPropertyList([self class], &outCount);
for (i = 0; i<outCount; i++)
{
objc_property_t property = properties[i];
const char *char_f =property_getName(property);
NSString *propertyName = [NSString stringWithUTF8String:char_f];
id propertyValue = [self valueForKey:(NSString *)propertyName];
if (propertyValue)
[props setObject:propertyValue forKey:propertyName];
}
free(properties);
return props;
}
- runtime之Ivar
//Ivar:表示類對(duì)象中的所有定義的全局變量
//獲取類的成員變量名
+ (NSArray *)getVariableNamesByObject:(id)object
{
unsigned int numIvars = 0;
//獲取類的所有成員變量
Ivar * ivars = class_copyIvarList([object class], &numIvars);
//定義一個(gè)數(shù)組來接收獲取的屬性名
NSMutableArray *nameArray = [[NSMutableArray alloc] initWithCapacity:numIvars];
for(int i = 0; i < numIvars; i++) {
//得到單個(gè)的成員變量
Ivar thisIvar = ivars[i];
//得到這個(gè)成員變量的類型
const char *type = ivar_getTypeEncoding(thisIvar);
NSString *stringType = [NSString stringWithCString:type encoding:NSUTF8StringEncoding];
//此處判斷非object-c類型時(shí)跳過
if (![stringType hasPrefix:@"@"]) {
continue;
}
//得到成員變量名
NSString *variableName = [NSString stringWithUTF8String:ivar_getName(thisIvar)];
[nameArray addObject:variableName];
//這個(gè)函數(shù)可以得到成員變量的值
//object_getIvar(object, thisIvar)
}
free(ivars);
return nameArray;
}
歡迎互相學(xué)習(xí)Github