我正在尝试以编程方式构建UI.如何让这个动作起作用?我正在与Swift一起开发.
viewDidLoad中的代码:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let myFirstLabel = UILabel()
let myFirstButton = UIButton()
myFirstLabel.text = "I made a label on the screen #toogood4you"
myFirstLabel.font = UIFont(name: "MarkerFelt-Thin", size: 45)
myFirstLabel.textColor = UIColor.redColor()
myFirstLabel.textAlignment = .Center
myFirstLabel.numberOfLines = 5
myFirstLabel.frame = CGRectMake(15, 54, 300, 500)
myFirstButton.setTitle("?", forState: .Normal)
myFirstButton.setTitleColor(UIColor.blueColor(), forState: .Normal)
myFirstButton.frame = CGRectMake(15, -50, 300, 500)
myFirstButton.addTarget(self, action: "pressed", forControlEvents: .TouchUpInside)
self.view.addSubview(myFirstLabel)
self.view.addSubview(myFirstButton)
}
func …
Run Code Online (Sandbox Code Playgroud) 我想在Swift中制作一个简单的动画.这是一个淡入淡出.
我试过:
self.myFirstLabel.alpha = 0
self.myFirstButton.alpha = 0
self.mySecondButton.alpha = 0
Run Code Online (Sandbox Code Playgroud)
然后,我有:
self.view.addSubview(myFirstLabel)
self.view.addSubview(myFirstButton)
self.view.addSubview(mySecondButton)
Run Code Online (Sandbox Code Playgroud)
然后:
UIView.animateWithDuration(1.5, animations: {
self.myFirstLabel.alpha = 1.0
self.myFirstButton.alpha = 1.0
self.mySecondButton.alpha = 1.0
})
Run Code Online (Sandbox Code Playgroud)
我在viewDidLoad函数中拥有所有这些.
我该如何工作?
在swift中,我正在将一个对象转换到视图中,我需要它滑入或淡入.如何在我的程序中获得这种类型的动画?
我没有IB(Interface Builder)以编程方式创建了所有视图元素
有文件我可以参考一下吗?我找不到任何东西.
我有一个选择器视图,我希望它中的东西是飞机的尾号.我使用这段代码,但是我得到警告Loop will run once at most, (loop increment never executed)
,然后我得到control may each end of non-void function.
错误这里有什么问题?
码:
- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
for (NSInteger i = [[NSUserDefaults standardUserDefaults]integerForKey:@"planeNum"]; (i = 0); i--) {
NSString *dTailNumber = [NSString stringWithFormat:@"%@", [[NSUserDefaults standardUserDefaults]objectForKey:[NSString stringWithFormat:@"Plane%liTailNumber", i]]];
return dTailNumber;
}
}
Run Code Online (Sandbox Code Playgroud) 在Swift中,我有一个包含三个对象的视图.我希望按钮和标签位于图像的顶部.这是一个像Photoshop中的图层一样的概念.目前,图像位于按钮和标签的顶部,因此您无法看到按钮和标签.这是怎么做到的?
我的代码在这里:
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let myFirstLabel = UILabel()
let myFirstButton = UIButton()
let myFirstImage = UIImage(named: "1792614.jpg")
let myFirstImageView = UIImageView(image: myFirstImage)
myFirstLabel.text = "I made a label on the screen #toogood4you"
myFirstLabel.font = UIFont(name: "MarkerFelt-Thin", size: 45)
myFirstLabel.textColor = UIColor.redColor()
myFirstLabel.textAlignment = .Center
myFirstLabel.numberOfLines = 5
myFirstLabel.frame = CGRectMake(15, 54, 300, 500)
myFirstButton.setTitle("?", forState: .Normal)
myFirstButton.setTitleColor(UIColor.blueColor(), forState: …
Run Code Online (Sandbox Code Playgroud)