Showing posts with label watchkit. Show all posts
Showing posts with label watchkit. Show all posts

Tuesday, March 24, 2015

Change font and size in watchkit

Change font and size in watchkit



  1. Create IBOutlet of your WKInterfaceLabel
  2. Create UIFont object

    UIFont
    * labelFont = [UIFont fontWithName:@"Courier-Bold" size:8];
  3. Create NSAttributedString object

    NSAttributedString *labelText = [[NSAttributedString alloc] initWithString : @"my Label string title" attributes : @{ NSKernAttributeName : @2.0, NSFontAttributeName : labelFont}];
  4. set attributedString to label

    [self.label setAttributedText:labelText];

Monday, October 13, 2014

detecting iOS, iPhone, iPad and apple watch

detecting iOS, iPhone, iPad and apple watch

// detecting iOS


NSString *version = [[UIDevice currentDevice] systemVersion];
NSLog(@"Version:%@",version);

//detecting iPhone



add these line to your .h file

#define IS_IPHONE_4 (fabs((double)[[UIScreen mainScreen]bounds].size.height - (double)480) < DBL_EPSILON)
#define IS_IPHONE_5 (fabs((double)[[UIScreen mainScreen]bounds].size.height - (double)568) < DBL_EPSILON)
#define IS_IPHONE_6 (fabs((double)[[UIScreen mainScreen]bounds].size.height - (double)667) < DBL_EPSILON)
#define IS_IPHONE_6_PLUS (fabs((double)[[UIScreen mainScreen]bounds].size.height - (double)736) < DBL_EPSILON)


and use it in your .m file

if (IS_IPHONE_4)
        NSLog(@"iPhone 4");
else if (IS_IPHONE_5)
        NSLog(@"iPhone 5");

//detecting iPad


if ([UIDevice currentDevice].userInterfaceIdiom != UIUserInterfaceIdiomPad)
{
        //code for iPad
}

//detecting apple watch

add these line to your .h file

#define IS_WATCH_42 (fabs((double)self.contentFrame.size.height - (double)174) < DBL_EPSILON)

#define IS_WATCH_38 (fabs((double)self.contentFrame.size.height - (double)151) < DBL_EPSILON)


and use it in your .m file

if (IS_WATCH_42)
        NSLog(@"apple watch 42mm");
    else if (IS_WATCH_38)
        NSLog(@"apple watch 38mm");