IOS日常開發中遇到的小問題

weixin_33716557發表於2016-09-01

1,UIButton 新增多行文字
解決方法:
1),如果兩行文字大小相同,顏色相同,可以直接設定Line Break為Word Wrap,然後在Title中按option+enter就可以增加行數。
2),要想兩行文字大小不同,顏色不同,那加一個UILabel作為UIButton的subview了應該是最方便的實現方式了。
2,使用帶xib的view
UINib *nib = [UINib nibWithNibName:@"AboutUsHeadView" bundle:nil];
AboutUsHeadView *header = [[nib instantiateWithOwner:nil options:nil] firstObject];
3,UIView上新增一個UIButton ,點選時間不響應,addTarget: action無效
解決方法:
1),檢查UIView的frame是否小於UIButton的frame
2),userInteractionEnabled = yes;
注意:如果是新增在UITableview headerView 或者 footerView上 需要用程式碼設定高度(這個很重要)
4,用程式碼繪製一個圖片
// 根據你尺寸和顏色,繪製一個純色的圖片
// @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 不提示自己寫的程式碼問題
解決方案:
1)、在Build Settings 的 search Paths 下的 User Header Search Paths 中雙擊右邊空白。然後點+號新增 $(PODS_ROOT) 程式碼,並在右邊的選項中選擇recursive選項。完成設定。然後我們匯入類庫進就會有提示了
2)、如果還是不行,可以試試如下方法。 同樣在Build Settings 中找到 Weak References in Manual Retain Release 選項,在右邊的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

//每個cell的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    CGFloat width = (SCREEN_WIDTH-5)/2.0;
    return CGSizeMake(width, width+70);
}
//設定每個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;
}
//設定頭部的高度
- (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+/ 註釋不能使用問題
終端下執行命令sudo /usr/libexec/xpccachectl,然後重啟即可

10,UIButton 圓角

 self.submitBtn.layer.masksToBounds = YES;
//如果想要設定圓形,button的長寬相等,cornerRadius等於寬度的一半
 self.submitBtn.layer.cornerRadius = 5.0;

相關文章