我试图在Swift中使用十六进制颜色值,而不是UIColor
允许你使用的几个标准颜色值,但我不知道如何去做.
示例:我将如何#ffffff
用作颜色?
我正在尝试使用Swift更改UIButton的字体...
myButton.font = UIFont(name: "...", 10)
Run Code Online (Sandbox Code Playgroud)
但是.font
已弃用,我不知道如何更改字体.
有什么建议?
我有一个名为class MyClass
的类UIView
,我想用XIB
文件初始化.我不知道如何使用调用的xib文件初始化此类View.xib
class MyClass: UIView {
// what should I do here?
//init(coder aDecoder: NSCoder) {} ??
}
Run Code Online (Sandbox Code Playgroud) 嗨,我有TableViewController
两个静态单元格,但是在显示时,它会显示两个静态单元格,然后是tableview的所有其他空单元格.但是我不想显示那些细胞,因为它们没用.如何将其余细胞隐藏在两个静电池之外?
我试图转换从UITextField获取的数字,我认为它实际上是字符串,并将它们转换为float,所以我可以将它们相乘.
我有两个UITextfield
s声明如下:
@IBOutlet var wage: UITextField
@IBOutlet var hour: UITextField
Run Code Online (Sandbox Code Playgroud)
当用户按下UIButton我想计算用户赚取的工资,但我不能,因为我需要先将它们转换为浮点数,然后再使用它们.
我知道如何通过这样做将它们转换为整数:
var wageConversion:Int = 0
wageConversion = wage.text.toInt()!
Run Code Online (Sandbox Code Playgroud)
但是,我不知道如何将它们转换为浮点数.
当用户按下UIButton时,我想从ViewController转换到secondViewController,只使用Swift中的代码.
//Function to transition
func transition(Sender: UIButton!)
{
//Current Code, default colour is black
let secondViewController:UIViewController = UIViewController()
self.presentViewController(secondViewController, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud) 我想添加"确定"按钮以外的其他按钮,它应该只是关闭警报.我想要另一个按钮来调用某个功能.
var logInErrorAlert: UIAlertView = UIAlertView()
logInErrorAlert.title = "Ooops"
logInErrorAlert.message = "Unable to log in."
logInErrorAlert.addButtonWithTitle("Ok")
Run Code Online (Sandbox Code Playgroud)
如何在此警报中添加另一个按钮,然后允许它在点击后调用一个函数,让我们说我们想要新的按钮来调用:
retry()
Run Code Online (Sandbox Code Playgroud) 我想在app delegate中设置rootViewController ..
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
var rootView: MyRootViewController = MyRootViewController()
//Code to set this viewController as the root view??
return true
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用以下代码(RGBA值)更改UITextField中的文本颜色,但它只是显示为白色或清晰,我不太确定,因为背景本身就是白色.
passwordTextField.textColor = UIColor(red: CGFloat(202.0), green: CGFloat(228.0), blue: CGFloat(230.0), alpha: CGFloat(100.0))
passwordTextField.returnKeyType = UIReturnKeyType.Done
passwordTextField.placeholder = "Password"
passwordTextField.backgroundColor = UIColor.clearColor()
passwordTextField.borderStyle = UITextBorderStyle.RoundedRect
passwordTextField.font = UIFont(name: "Avenir Next", size: 14)
passwordTextField.textAlignment = NSTextAlignment.Center
passwordTextField.secureTextEntry = true
Run Code Online (Sandbox Code Playgroud) 所以我想说我有一个名为Math的课程
class Math{
func add(numberOne: Int, numberTwo: Int) -> Int{
var answer: Int = numberOne + numberTwo
return answer
}
Run Code Online (Sandbox Code Playgroud)
在这个类中有一个允许用户添加两个数字的功能.
我现在有另一个类,它是UIViewController的子类,我想使用Math类的add函数,我该怎么做?
class myViewController: UIViewController{
//Math.add()???
}
Run Code Online (Sandbox Code Playgroud)