我试图集中一些文字,但我似乎没有工作.
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let title = UILabel()
title.text = "Some Sentence"
title.numberOfLines = 0
title.frame = CGRectMake(self.view.bounds.size.width/2,50,self.view.bounds.size.width, self.view.bounds.size.height) // x , y, width , height
title.textAlignment = .Center
title.sizeToFit()
title.backgroundColor = UIColor.redColor()
self.view.addSubview(title)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Run Code Online (Sandbox Code Playgroud)
这是我正在使用的代码,但这是我得到的:
它不是屏幕的中心.有人能告诉我我做错了什么吗?
我是新手,我很难解决这个问题.所以我需要做的是将此数组保存为iphone文档文件夹中的json文件.
var levels = ["unlocked", "locked", "locked"]
Run Code Online (Sandbox Code Playgroud)
然后才能将它读回另一个数组.有人可以告诉我该怎么做?或提供完成此操作的确切代码.
编辑:我找到了一个例子.这是他们设置数据的方式:
"[ {"person": {"name":"Dani","age":"24"}}, {"person": {"name":"ray","age":"70"}} ]"
Run Code Online (Sandbox Code Playgroud)
你可以这样访问它:
if let item = json[0]
{ if let person = item["person"]
{ if let age = person["age"]
{ println(age) } } }
Run Code Online (Sandbox Code Playgroud)
但我需要能够从保存在文档文件夹中的文件中执行相同的操作.
我刚开始使用swift进行ios开发,我无法弄清楚如何绘制圆圈.我只想绘制一个圆圈,将其设置为变量并显示在屏幕上,以便我以后可以将其用作主要播放器.谁能告诉我怎么做或者为我提供代码?
我在网上找到了这个代码:
var Circle = SKShapeNode(circleOfRadius: 40)
Circle.position = CGPointMake(500, 500)
Circle.name = "defaultCircle"
Circle.strokeColor = SKColor.blackColor()
Circle.glowWidth = 10.0
Circle.fillColor = SKColor.yellowColor()
Circle.physicsBody = SKPhysicsBody(circleOfRadius: 40)
Circle.physicsBody?.dynamic = true //.physicsBody?.dynamic = true
self.addChild(Circle)
Run Code Online (Sandbox Code Playgroud)
但当我把它放在xcode上运行应用程序时,游戏场景中没有任何内容.