1登疗,UIButton 添加多行文字
解決方法:
1)排截,如果兩行文字大小相同,顏色相同辐益,可以直接設(shè)置Line Break為Word Wrap断傲,然后在Title中按option+enter就可以增加行數(shù)。
2)智政,要想兩行文字大小不同认罩,顏色不同,那加一個(gè)UILabel作為UIButton的subview了應(yīng)該是最方便的實(shí)現(xiàn)方式了女仰。
2猜年,使用帶xib的view
UINib *nib = [UINib nibWithNibName:@"AboutUsHeadView" bundle:nil];
AboutUsHeadView *header = [[nib instantiateWithOwner:nil options:nil] firstObject];
3,UIView上添加一個(gè)UIButton 疾忍,點(diǎn)擊時(shí)間不響應(yīng)乔外,addTarget: action無(wú)效
解決方法:
1),檢查UIView的frame是否小于UIButton的frame
2)一罩,userInteractionEnabled = yes杨幼;
注意:如果是添加在UITableview headerView 或者 footerView上 需要用代碼設(shè)置高度(這個(gè)很重要)
4,用代碼繪制一個(gè)圖片
// 根據(jù)你尺寸和顏色,繪制一個(gè)純色的圖片
// @param size 圖片尺寸
// @param color 圖片顏色
// @return 繪制好的圖片
-(UIImage *)createImage:(CGSize)size color:(UIColor *)color{
UIGraphicsBeginImageContextWithOptions(size, YES, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, CGRectMake(0, 0, size.width, size.width));
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
5,xcode 不提示自己寫(xiě)的代碼問(wèn)題
解決方案:
1)聂渊、在Build Settings 的 search Paths 下的 User Header Search Paths 中雙擊右邊空白差购。然后點(diǎn)+號(hào)添加 $(PODS_ROOT) 代碼,并在右邊的選項(xiàng)中選擇recursive選項(xiàng)汉嗽。完成設(shè)置欲逃。然后我們導(dǎo)入類庫(kù)進(jìn)就會(huì)有提示了
2)、如果還是不行饼暑,可以試試如下方法稳析。 同樣在Build Settings 中找到 Weak References in Manual Retain Release 選項(xiàng),在右邊的Sqlite下方將NO改為YES.
6弓叛,storyboard 傳值
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:@"enterHomePageHeaderBtn"]) {
UIButton *btn = sender;
HomePageHeaderBtnActionController *homePageHeader = segue.destinationViewController;
homePageHeader.identifier = btn.titleLabel.text;
}
}
7, UICollectionView
//每個(gè)cell的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
CGFloat width = (SCREEN_WIDTH-5)/2.0;
return CGSizeMake(width, width+70);
}
//設(shè)置每個(gè)cell的上下左右的間距
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
return UIEdgeInsetsMake(0, 0, 10, 0);
}
//最小列間距
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
return 5;
}
//設(shè)置頭部的高度
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
return CGSizeMake(SCREEN_WIDTH, 344);
}
8彰居,取消UIButton的Target事件
[_rightBtn removeTarget:nil action:NULL forControlEvents:UIControlEventAllEvents];
9,xcode8 com+/ 注釋不能使用問(wèn)題
終端下執(zhí)行命令sudo /usr/libexec/xpccachectl撰筷,然后重啟即可
10陈惰,UIButton 圓角
self.submitBtn.layer.masksToBounds = YES;
//如果想要設(shè)置圓形,button的長(zhǎng)寬相等毕籽,cornerRadius等于寬度的一半
self.submitBtn.layer.cornerRadius = 5.0;