Last active
April 8, 2020 09:30
-
-
Save WikipediaBrown/e537060f90a0d15e5608f0fa3ea76c0a 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
import UIKit | |
// 1. Write a function that takes no arguments and returns a view that is the size of the screen and is colored red. The function should return an AnyObject instead of a UIView, since a UIView cannot pass the C/C++ boundary. | |
func gimmeUIView() -> AnyObject { | |
let newView = UIView(frame: UIScreen.mainScreen().bounds) | |
newView.backgroundColor = .redColor() | |
return newView | |
} | |
//2. Suppose that I have a function whose C interface is as follows: void GetProductDescription(const char * input, const char * output). This function takes text input and produces a product description in the output argument. Please write a function that takes a string input (in the language of your choice) and returns a view (AnyObject) that is a blue UILabel with the extracted product description written on the label in white text. | |
func gimmeUILabel(stringInput: String) -> AnyObject { | |
var output: [CChar] = [] | |
var descriptionOutput = "" | |
GetProductDescription(output, outdoor: output) | |
if output != [] { | |
descriptionOutput = String.fromCString(&output)! | |
} | |
let newlabel = UILabel(frame: CGRectMake(0,UIScreen.mainScreen().bounds.height/2, UIScreen.mainScreen().bounds.width, 50)) | |
let titleAttributes = [ | |
NSFontAttributeName: UIFont.preferredFontForTextStyle(UIFontTextStyleHeadline), | |
NSForegroundColorAttributeName: UIColor.whiteColor() | |
] | |
let titleString = NSMutableAttributedString(string: "\(descriptionOutput)", attributes: titleAttributes) | |
newlabel.attributedText = titleString | |
newlabel.textAlignment = .Center | |
newlabel.backgroundColor = .blueColor() | |
return newlabel | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment