IOS Swift SpriteKit Scaling Entire Views According to Frame Size

I would like the scenes of my game in SpriteKit to appear differently sized depending on the size of the device. Right now I am manually resizing and positioning some of my nodes with an 'if' statement checking for frame size, but unfortunately I cannot do this for all of my sprites due to the mechanics of my game (I am detecting collisions based off of the positions of my nodes, not by using PhysicsBodies. If I were to change the size of the nodes, these collisions would not be detected).Is there a way to scale the appearance of the view according to the device size inste...

Setting font requires size that overrides sizeToFit() Swift

I am making a label, and trying to set the font to "Avenir" like this: let usernameLabel: UILabel usernameLabel = UILabel(frame: CGRect(x: 20, y: third * screenHeight + sixth * screenHeight, width: third * screenWidth, height: 30)) usernameLabel.text = "Username" usernameLabel.font = UIFont(name: "Avenir", size: 30) // Where I set the font usernameLabel.sizeToFit() usernameLabel.textColor = UIColor.gray() self.view.addSubview(usernameLabel)However I want the size to adjust dynamically using usernameLabel.sizeToFit(), however this has not effect as I hav...

How to set a variable value in another class in Swift

How can I add a value to a variable in a class myClass2 from another class myClass in swift?I have already tried something like myClass2().myvariable = "value", but this didn't work; my variable value is still nil. here's the code:myViewController2:import UIKitclass MyViewController2: UIViewController { var myVariable : String?; @IBOutlet weak var display: UITextField! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarni...

Swift: Getting types from instance of a class

I have two files which I am working on for my SpriteKit game: SPSwipes.swift and GameScene.swift.In my SPSwipes.swift file, inside an SPSwipes class, a variable is triggered by an IBAction.class SPSwipes: UIViewController {@IBAction func fiveSwipes(sender: AnyObject) { var no_of_swipes = 5 }}In my GameScene.swift file, an if statement checks what value has been assigned to my variable, and creates an array thereof:if no_of_swipes == 5 { var array = Array<UInt32>(count: 5, repeatedValue: 0) for i in 0 ..< 5 { array[i] = arc4random_unif...

Application NightTime Mode

I have just finished creating my first application and would like to add some additional customisations to it. That is, in my settingsViewController I have added a switch which allows to set the colours to a nighttime mode. My questions is how can I actually get my application to do this.Thanks in advance for your responses. You can't expect this thing to be handled by iOS itself because its an app feature that you will have to implement.You can change background colors to dark and all those UILabel UIButton UITextView dark colored as well to have a feature called dark m...

How to verify (and require) self-signed certificate in iOS

I'd like to create an SSL connection to my server using self-signed certificates that are shipped with the code in iOS. That way I don't have to worry about more sophisticated man-in-the-middle attacks where someone has access to a high level "trusted" cert authority. I'm having issues doing so using what I believe to be Apple's standard way.Generating the certificate, via the procedure found here# Create root CA & private keyopenssl req -newkey rsa:4096 -sha512 -days 9999 -x509 -nodes -out root.pem.cer# Create a certificate signing requestopenssl req -newkey rsa:4096 -...

Upload file to S3 via multipart upload given temporary security credentials using AWS iOS SDK

My iOS application talks to a service(lets call this service "Service X") which is built on top of AWS. Service X provides RESTful APIs to upload content. When my application sends a PUT request to service X for creation of new asset, service X returns the information needed to perform multipart upload to S3. It contains "access key","secret key" & "session token" along with "asset_arn", "upload id" & "S3 URL for multipart uploads".I am not sure how to use this information to perform multipart uploads using AWS iOS SDK. The SDK provides Cognito to manage credentials...

Iterate all available tiles in cocos2d using CCTMXTiledMap

I'm using the CCTMXTiledMap class to load maps into the cocos2d game that I'm making. As part of the process, I would like to iterate through the properties of all available tiles in the tile sets associated with the .tmx map file -- INCLUDING ones that are not currently placed on a layer. In other words, I want to know max GID for tiles associated with the map. I want to do something like:for (int i = minGID; i < maxGID + 1; i++) { ... do something with the tiles by calling their GID... }How do I determine the minGID and maxGID associated with the .tmx file? Sinc...

Swift IOS Spritekit Scaling Sprite Size Based on Device Size

For the past couple of weeks I have been dabbling with SpriteKit, Xcode, and Swift and despite doing a lot of research I have yet to find out the best way to manage sprite size between devices.In my game I have found a somewhat round-about way of handling sprite size and position to make my sprites somewhat consistent between devices by manually adjusting characteristics like size, font size, and position with if statements checking for the height of the device. Ideally I would like my entire game views, including the sprites that they house, to be sized proportionally to t...

Embedding a UICollectionView in a UIScrollView works almost perfectly

BackgroundI embedded a UICollectionView inside of a UIScrollView and it works almost perfectly. GoalThe scrollable elements should pass off the scroll seamlessly once they've reached the end of their contentViews. When I swipe down on the UIScrollView it should scrolls down so that the UICollectionView takes up ~90% of the screen and then continues scrolling the collectionView. The reverse should be true as well, when I scroll up on the collectionView and reach the top of the collectionView content the scrollview should start scrolling up. Problem1) When I scroll up on the ...

How to get Sqlite Connection in Xamarin Forms in iOS?

I've created a Xamarin.Forms PCL project and trying to access the local data stored in sqlite database which is working file in Android but not working in iOS. Whenever I'm trying to call the iOS specific code using DependencyService it throws System.NullReferenceException: Object reference not set to an instance of an object.Here is my calling statementvar db = DependencyService.Get<IDBPath>().GetDBPath();Here is my iOS specific code for getting Sqlite Connectionusing SQLite.Net;using SQLite.Net.Async;using SQLite.Net.Platform.XamarinIOS;using SwachhParyatanApp.iOS;u...

Can't access variables from another class?

So I have a class named FoodListTable of type UITableViewControllerI also have a variable that finds the sum of elements in an array:var calorieTotal: Float { return calorieNumberArray.reduce(0 as Float) { $0 + Float($1) }}I did some tests, and this variable is computing correctly. However, when I try to use it in another class I named Menu, it computes to 0.0. I tried doing this: @IBAction func calculateButtonTappedMenu(sender: AnyObject) {let foodListTableAccess = FoodListTable()let dividend = foodListTableAccess.calorieTotalBut when I do this, var calorieTotal still c...

Swift - Typealias dictionary with value that implements a generic protocol

I want to typealias a dictionary of String keys and values of objects/structs that implements the Equatable protocol. So I wrote this line of code but it gave me error that I didn't know how to go on to fix.typealias Storage = [String: Equatable]I want to use the type [String: Equatable] as a variable in a protocol, e.g:protocol StorageModel { var storage: Storage { get set } init(storage: Storage)}Error: Protocol 'Equatable' can only be used as a generic constraint because it has Self or associated type requirementsCan anyone suggest a solution? Generally speaki...

Creating multiple instances of a class in do-while loop iOS

I am creating an app that takes information from a plist to create an electronic catalogue. We have many different versions, and it would be nice if I didn't have to go into the code for each app and set this number of sections for each one, and every time we make an update. I want to use a do while loop to accomplish this, but can't figure out how to rename my instance for each one. Please see the attached code, any help would be greatly appreciated!scroller = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 44, 320, 387)];int secNum = 8;int secTemp = 0;int frameWidth = s...

UILabel Align Text to center

How do I align text in UILabel? From iOS 6 and later UITextAlignment is deprecated. use NSTextAlignmentmyLabel.textAlignment = NSTextAlignmentCenter;Swift Version from iOS 6 and later myLabel.textAlignment = NSTextAlignment.center [XXX]Here is a sample code showing how to align text using UILabel:label = [[UILabel alloc] initWithFrame:CGRectMake(60, 30, 200, 12)];label.textAlignment = NSTextAlignmentCenter;You can read more about it here UILabel [XXX]To center text in a UILabel in Swift (which is targeted for iOS 7+) you can do:myUILabel.textAlignment = .CenterOrmy...

How can I add a image into uiwebview

In iOS, I need to load a website in uiwebview and I want to add a local image at the beginning of the webpage.I added < img src="logo.png"/> after < body > tag but it only showed a null pic(a small white box).How can I load my local image as the src of the img inside the html? Thanks Using relative paths or file: paths to refer to images does not work with UIWebView. Instead you have to load the HTML into the view with the correct baseURL:NSString *path = [[NSBundle mainBundle] bundlePath];NSURL *baseURL = [NSURL fileURLWithPath:path];[webView loadHTMLString:htmlSt...

Page 1 of 829  |  Show More Pages:  Top Prev Next Last