Skip to content

Commit

Permalink
Add storyboard example
Browse files Browse the repository at this point in the history
  • Loading branch information
bernedom committed Jul 7, 2024
1 parent 9b3641e commit e62e381
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 3 deletions.
2 changes: 1 addition & 1 deletion chapter16/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ project(
VERSION 1.0
DESCRIPTION
"Examples for chapter 16 of the CMake Best Practices book"
LANGUAGES CXX
LANGUAGES CXX OBJCXX
)

# The examples in this chapter are apple specific
Expand Down
2 changes: 1 addition & 1 deletion chapter16/app_bundle_example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ project(
VERSION 1.0
DESCRIPTION
"A simple C++ project to demonstrate an apple ui"
LANGUAGES CXX
LANGUAGES CXX OBJCXX
)

# Add the executable
Expand Down
20 changes: 20 additions & 0 deletions chapter16/app_bundle_storyboard/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 3.25)

# Project name and version
project(
ch16_app_bundle_storyboard
VERSION 1.0
DESCRIPTION
"A simple C++ project to demonstrate an apple ui"
LANGUAGES CXX OBJCXX
)

set(resource_files
${CMAKE_CURRENT_SOURCE_DIR}/storyboards/Main.storyboard
)

# Add the executable
add_executable(ch16_app_bundle_storyboard MACOSX_BUNDLE src/main.mm)
target_sources(ch16_app_bundle_storyboard PRIVATE ${resource_files})

set_source_files_properties(${resource_files} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
55 changes: 55 additions & 0 deletions chapter16/app_bundle_storyboard/src/main.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#import <UIKit/UIKit.h>

// AppDelegate Interface
@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property(strong, nonatomic) UIWindow *window;

@end

// ViewController Interface
@interface ViewController : UIViewController

@end

// ViewController Implementation
@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];
// Additional setup if needed
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 200, 300, 50)];
label.text = @"Hello, World!";
label.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:label];
}

@end

// AppDelegate Implementation
@implementation AppDelegate

- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main"
bundle:nil];
ViewController *viewController =
[storyboard instantiateViewControllerWithIdentifier:@"ViewController"];

self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];

return YES;
}

@end

// Main
int main(int argc, char *argv[]) {
@autoreleasepool {
return UIApplicationMain(argc, argv, nil,
NSStringFromClass([AppDelegate class]));
}
}
36 changes: 36 additions & 0 deletions chapter16/app_bundle_storyboard/storyboard/main.storyboard
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12118" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12104"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="HelloWorld" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Hello, World!" textAlignment="center" lineBreakMode="tailTruncation" adjustsFontSizeToFit="NO" id="dGj-vS-cMf">
<rect key="frame" x="87" y="284" width="200" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="dGj-vS-cMf" firstAttribute="centerX" secondItem="6Tk-OE-BBY" secondAttribute="centerX" id="c8C-rD-C8u"/>
<constraint firstItem="dGj-vS-cMf" firstAttribute="centerY" secondItem="6Tk-OE-BBY" secondAttribute="centerY" id="iaY-PA-aYv"/>
</constraints>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYk-Nv-e0C" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
</document>
2 changes: 1 addition & 1 deletion chapter16/hello_world_apple/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ project(
VERSION 1.0
DESCRIPTION
"A simple C++ project to demonstrate an apple ui"
LANGUAGES CXX
LANGUAGES CXX OBJCXX
)

# set some global XCode properties
Expand Down

0 comments on commit e62e381

Please sign in to comment.