1.if (![selfgestureRecognizers]) {
self.userInteractionEnabled =YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizeralloc] initWithTarget:selfaction:@selector(tap)];
[selfaddGestureRecognizer:tap];
}
2.
- -(NSArray *)userNameArray{
if (_jobDict) {
if (!_userNameArray) {
_userNameArray = [[NSMutableArray alloc]init];
NSArray *keys = [_jobDictallKeys];
keys = [keys sortedArrayUsingComparator:^NSComparisonResult(id obj1,id obj2) {
return [obj1compare:obj2 options:NSNumericSearch];
}];
for (NSString *keyin keys) {
[_jobNameArrayaddObject:[_jobDictobjectForKey:key]];
}
}
return_jobNameArray;
}else{
return@[@"暂无选项"];
}
}
//将数组中的元素按降序排列
3.
//通过索引得到字典中的value 字段
- (NSString *)jobNameWithIndex:(NSNumber *)index{
NSString *jobName;
if (_jobDict) {
jobName = [_jobDictobjectForKey:index.stringValue];
}else{
jobName = nil;
}
return jobName;
}
//通过字段名获取得到字典索引
- (NSNumber *)indexOfJobName:(NSString *)job_str{
NSInteger index =0;
if (_jobNameArray) {
index = [_jobNameArrayindexOfObject:job_str];
}
if (index ==NSNotFound) {
index = 0;
}
return [NSNumbernumberWithInteger:index];
}
4.//根据字体获取宽高
- (CGSize)getSizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size{
CGSize resultSize = CGSizeZero;
if (self.length <=0) {
return resultSize;
}
resultSize = [selfboundingRectWithSize:size
options:(NSStringDrawingUsesFontLeading |NSStringDrawingUsesLineFragmentOrigin)
attributes:@{NSFontAttributeName: font}
context:nil].size;
resultSize =CGSizeMake(MIN(size.width, ceilf(resultSize.width)),MIN(size.height, ceilf(resultSize.height)));
return resultSize;
}
- (CGFloat)getHeightWithFont:(UIFont *)font constrainedToSize:(CGSize)size{
return [selfgetSizeWithFont:font constrainedToSize:size].height;
}
5.使用runtime kvc 进行字典转模型。