2014-09-23 8 views
7

अब आईओएस 8 ने UIActionsheet और UIAlertview को बहिष्कृत किया है IOS7 पर काम कर रहे अनुकूलन अब और प्रभावी नहीं हो रहा है। अभी तक एकमात्र अनुकूलन मुझे पता है टिंट रंग है। और मुझे जो चाहिए वह शीर्षक के फ़ॉन्ट आकार और शैली को बदल रहा है जिसे मुझे नए UIAlertAction के साथ ऐसा करने का कोई तरीका नहीं मिला है।क्या UIAlertAction शीर्षक फ़ॉन्ट आकार और शैली को संपादित करना संभव है?

Already referred to this लेकिन मुझे उम्मीद है कि कम से कम शीर्षक आकार और फ़ॉन्ट को बदलने का एक तरीका है।

आप के लिए UIAlertAction

UIAlertController * alertActionSheetController = [UIAlertController alertControllerWithTitle:@"Settings" 
                       message:@"" 
                     preferredStyle:UIAlertControllerStyleActionSheet]; 
    UIAlertAction * aboutTheAppAction = [UIAlertAction actionWithTitle:@"About the App" 
                   style:UIAlertActionStyleDefault 
                   handler:^(UIAlertAction * action){ 
                    NSLog(@"About the app"); 
                    [self openAbout]; 

                   }]; 


[alertActionSheetController addAction:aboutTheAppAction]; 
[self presentViewController:alertActionSheetController animated:YES completion:nil]; 
+0

नज़र इस https://github.com/ianb821/IBActionSheet –

+0

खैर उस के लिए दोनों के बाद से यह UIView का एक नया उपवर्ग से बना है, लेकिन मैं क्या तलाश कर रहा हूँ स्टाइल को संपादित करने के तरीके है काम करेंगे एक चेतावनी का। – Teffi

उत्तर

12

आप UIAlertAction के फ़ॉन्ट और रंग बदल सकते हैं मेरी कोड के कुछ प्रदान करना। पहले तुम भी यूआरएल निम्न https://www.dropbox.com/s/em91fh00fv3ut4h/Archive.zip?dl=0

पर अपलोड कर रहा है यही कारण है कि फ़ाइल आप समारोह निम्नलिखित कॉल करने की आवश्यकता आयात करने के बाद जोड़ने के लिए UILabel श्रेणी

@interface UILabel (FontAppearance) 
@property (nonatomic, copy) UIFont * appearanceFont UI_APPEARANCE_SELECTOR; 
@end 

@implementation UILabel (FontAppearance) 

-(void)setAppearanceFont:(UIFont *)font { 
    if (font) 
     [self setFont:font]; 
} 

-(UIFont *)appearanceFont { 
    return self.font; 
} 

@end 

श्रेणी फाइल की जरूरत है।

UILabel * appearanceLabel = [UILabel appearanceWhenContainedIn:UIAlertController.class, nil]; 
[appearanceLabel setAppearanceFont:yourDesireFont]]; 

ऊपर कोड रंग और फ़ॉन्ट पर परीक्षण किया जाता है। और यह केवल आईओएस 8 या उससे अधिक के लिए मान्य होगा।

+0

यह UIAlertController के दृश्य में सभी लेबलों के लिए फ़ॉन्ट को बदलता है। – p0lAris

+0

को लिखने के उत्तर के रूप में स्वीकार किया जाना चाहिए! –

+0

धन्यवाद मेरे लिए काम किया। मैंने इसे अपनी खुद की यूलाबेल श्रेणी में रखा था जो मेरे पास पहले से था, और संपत्ति घोषणा .h में मैंने उन नए चयनकर्ताओं के लिए विधि घोषणाओं को .h के साथ-साथ आयात किया। मैंने आयात किया .h जहां मैंने उपयोग किया UIAlertController –

0

निजी एपीआई का उपयोग करके चेतावनी कार्रवाई के फ़ॉन्ट को बदलना संभव है। यह आपको ऐप खारिज कर सकता है, मैंने अभी तक इस तरह के कोड जमा करने की कोशिश नहीं की है। पर

let alert = UIAlertController(title: nil, message: nil, preferredStyle: .ActionSheet) 

let action = UIAlertAction(title: "Some title", style: .Default, handler: nil)let attributedText = NSMutableAttributedString(string: "Some title") 

let range = NSRange(location: 0, length: attributedText.length) 
attributedText.addAttribute(NSKernAttributeName, value: 1.5, range: range) 
attributedText.addAttribute(NSFontAttributeName, value: UIFont(name: "ProximaNova-Semibold", size: 20.0)!, range: range) 

alert.addAction(action) 

presentViewController(alert, animated: true, completion: nil) 

// this has to be set after presenting the alert, otherwise the internal property __representer is nil 
guard let label = action.valueForKey("__representer")?.valueForKey("label") as? UILabel else { return } 
label.attributedText = attributedText 
संबंधित मुद्दे