** 好記性不如爛筆頭 記錄一些自己在開發(fā)中經(jīng)常用到的一些瑣碎代碼片段 會經(jīng)常更新 .. **
1苍凛、目前iOS項目中要求導(dǎo)航欄的返回按鈕只保留那個箭頭奈惑,去掉后邊的文字萤悴,在網(wǎng)上查了一些資料丢早,最簡單且沒有副作用的方法就是
[UIBarButtonItem appearance]setBackButtonTitlePositionAdjustment:UIOffsetMake(0,-60)] for BarMetrics:UIBarMetricsDefault];
2璧疗、簡單實現(xiàn)一個導(dǎo)航欄的下的提示視圖 效果如下
- (void)showNewStatusesCount:(NSInteger)nums{
UILabel *label = [[UILabel alloc] init];
label.font = [UIFont systemFontOfSize:12];
if (nums) {
label.text = [NSString stringWithFormat:@"新%ld條數(shù)據(jù)", count];
} else {
label.text = @"暫無新數(shù)據(jù)";
}
label.backgroundColor = [UIColor colorWithRed:0/255.0 green:174/255.0 blue:22/255.0 alpha:1.0];
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor whiteColor];
label.width = self.view.frame.size.width;
label.height = 35;
label.x = 0;
label.y = CGRectGetMaxY([self.navigationController navigationBar].frame) - label.frame.size.height;
[self.navigationController.view insertSubview:label belowSubview:self.navigationController.navigationBar];
[UIView animateWithDuration:.8f; animations:^{
label.transform = CGAffineTransformMakeTranslation(0, label.frame.size.height);
} completion:^(BOOL finished) { /
[UIView animateWithDuration:duration delay:.8f options:UIViewAnimationOptionCurveEaseInOut animations:^{
label.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished) {
[label removeFromSuperview];
}];
}];
}
3坯辩、平時有用到更改label的行間距 使其排版看起來更美觀