Advertisement
jerusso

Obj-C Example

Jun 19th, 2019
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. //  JbD_Opus001_MainViewController.m
  3. //  Pixel Coder
  4. //
  5. //  Created by John E Russo on 1/9/13.
  6. //  Copyright (c) 2013-2014 John E Russo. All rights reserved.
  7. //
  8.  
  9. #import "JbD_Opus001_MainViewController.h"
  10. #import "JbD_Opus001_Converter.h"
  11. #import "Constants.h"
  12.  
  13. @implementation JbD_Opus001_MainViewController
  14. {
  15.     JbD_Opus001_Converter *myConverter;
  16. }
  17.  
  18. @synthesize noBaseValueAlert, noConversionValueAlert, displayString, mainTextField, insetLabel, baseValueLabel, baseButton, firstConversionView, secondConversionView, thirdConversionView, pxUOMLabel, ptUOMLabel, percentUOMLabel, emsUOMLabel, pxValueLabel, ptValueLabel, percentValueLabel, emsValueLabel;
  19.  
  20. - (void)viewDidLoad
  21. {
  22.    
  23.     [super viewDidLoad];
  24.    
  25.     //init alert views
  26.     noBaseValueAlert = [[UIAlertView alloc] initWithTitle:@"No Base Value" message:@"Enter a non-zero value and tap the Set Base button" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
  27.     noConversionValueAlert = [[UIAlertView alloc] initWithTitle:@"No Conversion Value" message:@"Enter a value and tap a conversion button" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
  28.    
  29.     //init displayString
  30.     displayString = [NSMutableString stringWithCapacity:4];
  31.    
  32.     //init Converter
  33.     myConverter = [[JbD_Opus001_Converter alloc] init];
  34.    
  35.     //set nav controller's view b/g color
  36.     self.view.backgroundColor = kMyGray;
  37.    
  38.     //grab nav bar from nav controller
  39.     UINavigationBar *mainNavBar = [self.navigationController navigationBar];
  40.    
  41.     //change nav bar b/g to black
  42.     mainNavBar.barStyle = UIBarStyleBlack;
  43.    
  44.     //customize title text
  45.     NSDictionary *titleTextProperties = [[NSDictionary alloc] initWithObjectsAndKeys:[UIFont fontWithName:@"Helvetica" size:18.0f], NSFontAttributeName, [UIColor whiteColor], NSForegroundColorAttributeName, nil];
  46.     mainNavBar.titleTextAttributes = titleTextProperties;
  47.     self.title = @"Pixel Coder";
  48.    
  49.     //build and add first conversion view
  50.     CGRect firstConversionViewRect = CGRectMake(0.0f, 188.0f, 320.f, 73.0f);
  51.     firstConversionView = [[UIView alloc] initWithFrame:firstConversionViewRect];
  52.     firstConversionView.translatesAutoresizingMaskIntoConstraints = NO;
  53.     firstConversionView.backgroundColor = [UIColor blackColor];
  54.     [self.view addSubview:firstConversionView];
  55.    
  56.     //build and add second conversion view
  57.     CGRect secondConversionViewRect = CGRectMake(0.0f, 262.0f, 320.f, 76.0f);
  58.     secondConversionView = [[UIView alloc] initWithFrame:secondConversionViewRect];
  59.     secondConversionView.translatesAutoresizingMaskIntoConstraints = NO;
  60.     secondConversionView.backgroundColor = [UIColor blackColor];
  61.     [self.view addSubview:secondConversionView];
  62.    
  63.     //build and add third conversion view
  64.     CGRect thirdConversionViewRect = CGRectMake(0.0f, 339.0f, 320.f, 77.0f);
  65.     thirdConversionView = [[UIView alloc] initWithFrame:thirdConversionViewRect];
  66.     thirdConversionView.translatesAutoresizingMaskIntoConstraints = NO;
  67.     thirdConversionView.backgroundColor = [UIColor blackColor];
  68.     [self.view addSubview:thirdConversionView];
  69.    
  70.     //constraints for conversion views
  71.     [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-(>=188)-[firstConversionView(73)]-1-[secondConversionView(76)]-1-[thirdConversionView(77)]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(firstConversionView, secondConversionView, thirdConversionView)]];
  72.     [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[firstConversionView(320)]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(firstConversionView, secondConversionView, thirdConversionView)]];
  73.     [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[secondConversionView(320)]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(firstConversionView, secondConversionView, thirdConversionView)]];
  74.     [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[thirdConversionView(320)]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(firstConversionView, secondConversionView, thirdConversionView)]];
  75.    
  76.    
  77.     //build and add percent UOM label
  78.     CGRect percentUOMLabelRect = CGRectMake(260.0f, 20.0f, 30.0f, 30.0f);
  79.     NSParagraphStyle *percentUOMLabelStyle = [NSParagraphStyle defaultParagraphStyle];
  80.     NSDictionary *percentUOMLabelTextDictionary = [[NSDictionary alloc]initWithObjectsAndKeys:[UIFont fontWithName:@"Helvetica" size:24.0f], NSFontAttributeName,[UIColor whiteColor], NSForegroundColorAttributeName, percentUOMLabelStyle, NSParagraphStyleAttributeName, nil];
  81.     NSAttributedString *percentUOMLabelText = [[NSAttributedString alloc] initWithString: @"%" attributes:percentUOMLabelTextDictionary];
  82.     percentUOMLabel = [[UILabel alloc] initWithFrame:percentUOMLabelRect];
  83.     percentUOMLabel.attributedText = percentUOMLabelText;
  84.     percentUOMLabel.backgroundColor = [UIColor clearColor];
  85.    
  86.     //build and add ems UOM Label
  87.     CGRect emsUOMLabelRect = CGRectMake(260.0f, 20.0f, 35.0f, 30.0f);
  88.     NSParagraphStyle *emsUOMLabelStyle = [NSParagraphStyle defaultParagraphStyle];
  89.     NSDictionary *emsUOMLabelTextDictionary = [[NSDictionary alloc]initWithObjectsAndKeys:[UIFont fontWithName:@"Helvetica" size:24.0f], NSFontAttributeName,[UIColor whiteColor], NSForegroundColorAttributeName, emsUOMLabelStyle, NSParagraphStyleAttributeName, nil];
  90.     NSAttributedString *emsUOMLabelText = [[NSAttributedString alloc] initWithString: @"em" attributes:emsUOMLabelTextDictionary];
  91.     emsUOMLabel = [[UILabel alloc] initWithFrame:emsUOMLabelRect];
  92.     emsUOMLabel.attributedText = emsUOMLabelText;
  93.     emsUOMLabel.backgroundColor = [UIColor clearColor];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement