UIPreviewAction 글꼴 색상에 대한 흑마법

1841 단어
****3D-터치를 사용할 때 UIPreviewAction을 생각해서 썼는데 글씨체의 색깔이 수정되지 않는 것을 보고 하나를 실행할 때 수정을 시도해 보았는데 정말 성공했다고 생각했어요.아래 위 코드 ****
@property (nonatomic,strong) UIColor *tintColor; /**<                 */

- (UIColor *)tintColor {

return objc_getAssociatedObject(self, @selector(tintColor));
}
- (void)setTintColor:(UIColor *)tintColor {

unsigned int count = 0;
Ivar *ivars = class_copyIvarList([UIPreviewAction class], &count);
for(int i = 0;i < count;i ++){
    
    Ivar ivar = ivars[i];
    NSString *ivarName = [NSString stringWithCString:ivar_getName(ivar) encoding:NSUTF8StringEncoding];
    NSLog(@"%@",ivarName);
    //    
    if ([ivarName isEqualToString:@"_color"] && tintColor) {
        
        [self setValue:tintColor forKey:@"color"];
    }
}

free(ivars);


objc_setAssociatedObject(self, @selector(tintColor), tintColor, OBJC_ASSOCIATION_RETAIN_NONATOMIC);

}

이때 외부에서 호출
#pragma mark -- /*3DTouch-Delegate*/ 
- (NSArray> *)previewActionItems {

    __weak typeof(self) weakSelf = self;

    UIPreviewAction *saveAction = [UIPreviewAction actionWithTitle:@"     " style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
    
        UIImageWriteToSavedPhotosAlbum(weakSelf.imageView.image, weakSelf, @selector(image:didFinishSavingWithError:contextInfo:),nil);
    
}];
    saveAction.tintColor = [UIColor blackColor];
    
    UIPreviewAction *cancellAction = [UIPreviewAction actionWithTitle:@"  " style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
    
}];
    cancellAction.tintColor = [UIColor blackColor];
    return @[saveAction,cancellAction];
}

좋은 웹페이지 즐겨찾기