Last active
May 6, 2019 16:54
-
-
Save DonMag/afd8797613545d02d4dbf5ec6d04804d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// AppDelegate.h | |
// | |
// Created by Don Mag on 4/8/19. | |
// | |
#import <UIKit/UIKit.h> | |
@interface AppDelegate : UIResponder <UIApplicationDelegate> | |
{ | |
} | |
@property (strong, nonatomic) UIWindow *window; | |
@end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// AppDelegate.m | |
// | |
// Created by Don Mag on 4/8/19. | |
// | |
#import "AppDelegate.h" | |
#import "TestViewController.h" | |
@interface AppDelegate () | |
@property (strong, nonatomic) TestViewController *testVC; | |
@end | |
@implementation AppDelegate | |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { | |
// Override point for customization after application launch. | |
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; | |
_testVC = [TestViewController new]; | |
_window.rootViewController = _testVC; | |
[_window makeKeyAndVisible]; | |
return YES; | |
} | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// TestViewController.h | |
// | |
// Created by Don Mag on 5/6/19. | |
// | |
#import <UIKit/UIKit.h> | |
@interface TestViewController : UIViewController | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// TestViewController.m | |
// | |
// Created by Don Mag on 5/6/19. | |
// | |
#import "TestViewController.h" | |
@interface TestViewController () | |
@end | |
@implementation TestViewController | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
// make sure we're seeing the correct view filling the window | |
self.view.backgroundColor = [UIColor orangeColor]; | |
// create a button | |
UIButton *aButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; | |
// blue background | |
aButton.backgroundColor = [UIColor blueColor]; | |
// white text | |
[aButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; | |
// set the title | |
[aButton setTitle:@"Test Button" forState:UIControlStateNormal]; | |
// add the button to the view | |
[self.view addSubview:aButton]; | |
// we'll use auto-layout constraints | |
[aButton setTranslatesAutoresizingMaskIntoConstraints:NO]; | |
// constrain button centerX and centerY | |
[NSLayoutConstraint activateConstraints: | |
@[ | |
[aButton.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor], | |
[aButton.centerYAnchor constraintEqualToAnchor:self.view.centerYAnchor] | |
// or | |
//[aButton.centerXAnchor constraintEqualToAnchor:aButton.superview.centerXAnchor], | |
//[aButton.centerYAnchor constraintEqualToAnchor:aButton.superview.centerYAnchor] | |
] | |
]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment