** 好記性不如爛筆頭 記錄一些自己在開發中經常用到的一些瑣碎代碼片段 會經常更新 .. **
1、目前iOS項目中要求導航欄的返回按鈕只保留那個箭頭,去掉后邊的文字,在網上查了一些資料,最簡單且沒有副作用的方法就是
[UIBarButtonItem appearance]setBackButtonTitlePositionAdjustment:UIOffsetMake(0,-60)] for BarMetrics:UIBarMetricsDefault];
2、簡單實現一個導航欄的下的提示視圖 效果如下
未命名.gif
- (void)showNewStatusesCount:(NSInteger)nums{
UILabel *label = [[UILabel alloc] init];
label.font = [UIFont systemFontOfSize:12];
if (nums) {
label.text = [NSString stringWithFormat:@"新%ld條數據", count];
} else {
label.text = @"暫無新數據";
}
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的行間距 使其排版看起來更美觀
屏幕快照 2017-01-17 下午2.25.27.png