iOS一些小技巧 | 三

一,UIButton让其文字在图片下方:

[operateBt setTitleEdgeInsets:UIEdgeInsetsMake(operateBt.imageView.frame.size.height+14.0, -operateBt.imageView.frame.size.width, 0.0, 0.0)];
[operateBt setImageEdgeInsets:UIEdgeInsetsMake(0.0, 0.0, 0.0, -operateBt.titleLabel.bounds.size.width)];

二,UIButton用SF符号:

        let image = UIImage(named: "record_def_svg")
        
        var config = UIImage.SymbolConfiguration(font: systemFontWithSize(ScaleSize(152.0)));
        if #available(iOS 15.0, *) {
            config = config.applying(UIImage.SymbolConfiguration(paletteColors: [.white]));
        }else {
            image?.withTintColor(.white, renderingMode: .alwaysOriginal);
        }
        image?.withTintColor(.white, renderingMode: .alwaysTemplate);
        recordButton.setImage(image, for: .normal);
        recordButton.setPreferredSymbolConfiguration(config, forImageIn: .normal);

3,主线程返回一个值:

- (BOOL)isBool {
    __block BOOL result;
    if ([NSThread isMainThread]) {
        return YES;
    } else {
        dispatch_sync(dispatch_get_main_queue(), ^{
            result = YES;
        });
    }
    return result;
}

Leave a Reply

Your email address will not be published. Required fields are marked *