小编ale*_*lex的帖子

如何以编程方式创建UIImage视图 - Swift

我正在尝试以编程方式创建UIImage视图,我有一个新视图,我尝试这样做

let imageName = "yourImage.png"
yourview.backgroundColor = UIColor.colorWithPatternImage(UIImage(named:imageName))
Run Code Online (Sandbox Code Playgroud)

这不起作用,因为我不知道这应该是在第二行的观点.

问题: 如何通过编码将UIImageView显示在屏幕上,而不是在故事板中进行

xcode uiimageview uiimage ios swift

93
推荐指数
7
解决办法
20万
查看次数

UIDatePicker减去确切时间 - Swift

我正在制作一个闹钟,它会告诉你你有多少小时和几分钟的睡眠时间.我设置了一个UIDatePicker用户选择他们想要醒来的时间.它还告诉了第二个确切的时间.我坚持的部分是他们将要睡多少小时.我试过基本上从中减去确切的时间UIDatePicker.如果它们都在AM中,这就有效.例如,如果用户想要在上午10:30醒来并且是上午9:30,那么您所要做的就是从9:30减去10:30以获得1小时.我很快意识到,如果它们是不同的时间,例如AM或PM,这将不起作用.

我如何从UIDatePicker获得时间

func handler(sender: UIDatePicker) {
        var timeFormatter = NSDateFormatter()
        timeFormatter.timeStyle = NSDateFormatterStyle.ShortStyle

        var strDate = timeFormatter.stringFromDate(theDatePicker.date)


    }
theDatePicker.addTarget(self, action: Selector("handler:"), forControlEvents: UIControlEvents.ValueChanged)
Run Code Online (Sandbox Code Playgroud)

我怎么得到了确切的时间

var date = NSDate()
var outputFormat = NSDateFormatter()
outputFormat.locale = NSLocale(localeIdentifier:"en_US")
outputFormat.dateFormat = "HH:mm:ss"
timeLabel.text = (outputFormat.stringFromDate(date))
var timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: Selector("getTime"), userInfo: nil, repeats: true)
Run Code Online (Sandbox Code Playgroud)

我的问题:

如何UIDatePicker从准确的时间中减去用户获得的睡眠时间?

theff

nsdate ios nsdatepicker swift

5
推荐指数
2
解决办法
3931
查看次数

按下按钮时动态更改标签 - iOS Swift

其中有按钮,当按下它们时,我希望将标签更改为该操作顺序,例如,当按下减法按钮时,我希望将符号更改为减法符号。这是故事板的图片。https://www.dropbox.com/s/sh61xss16xr2t0t/Screenshot%202014-10-11%2022.05.48.png?dl=0 当我按下不同的按钮时,我希望操作标志动态变化。

    @IBAction func addFunctionButtonPressed(sender: AnyObject) {
        //Adding Function
    }

    @IBAction func subtractionFunctionButtonPressed(sender: UIButton) {
        //Subtracting Function
    }

    @IBAction func multiplicationFunctionButtonPressed(sender: UIButton) {
        //Multiplication Function
    }

    @IBAction func divisionFunctionButtonPressed(sender: UIButton) {
        //Divivsion Function
    }
Run Code Online (Sandbox Code Playgroud)

这是在 Swift 编程语言中完成的

如果您有任何问题或疑虑,请在下方评论

ios swift

3
推荐指数
1
解决办法
2万
查看次数

如何从UIDatePicker获取数据 - Swift

我正在尝试从UIDatePicker获取数据,例如用户选择了一个日期为7:15 PM如何从中获取数据,以便我可以操作并将其用于其他功能?

如果您有任何疑问或需要任何澄清,请在下面评论.

ios swift

3
推荐指数
1
解决办法
6528
查看次数

无法同时满足约束 - Swift

摘要: 我刚刚完成自动布局,当我运行它时,它全部被挤在一起。然后我查看命令提示符,它显示上面的错误。我尝试用谷歌搜索它,但它只显示了 Obj-C 的解决方案,而我正在 Swift 中进行。我该如何解决这个自动布局问题?

错误:

2014-10-20 00:07:41.102 Fraction Calculator[74247:6698760] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) …
Run Code Online (Sandbox Code Playgroud)

xcode ios swift

2
推荐指数
1
解决办法
1万
查看次数

如何将小数转换为分数 - Swift

我有一个分数计算器,当我计算它时,它变成一个小数.我想把它变成一个分数.我不知道如何在代码中做到这一点,但我尝试分离计算,但它不起作用这里的代码与我的故事板的截图 https://www.dropbox.com/s/fmapxaou49zap05/iOS%20Simulator %20Screen%20Shot%20Oct%2015%2C%202014%2C%209.37.43%20 PM.png?DL = 0

        //Adding Function
        changingSignsLabel.text = "+"
        let firstDenomInTextField:Double! = (firstDenominatorTextField.text as NSString).doubleValue
        let firstNumInTextField:Double! = (firstNumeratorTextField.text as NSString).doubleValue
        let firstWholeInTextField:Double! = (firstWholeNumberTextField.text as NSString).doubleValue

        let secondDenomInTextField:Double! = (secondDenominatorTextField.text as NSString).doubleValue
        let secondNumInTextField:Double! = (secondNumeratorTextField.text as NSString).doubleValue
        let secondWholeInTextField:Double! = (secondWholeNumberTextField.text as NSString).doubleValue

        var firstStep = firstDenomInTextField! * firstWholeInTextField! / firstDenomInTextField!

        var secondStep = firstStep + firstNumInTextField! / firstDenomInTextField!

        var thirdStep = secondDenomInTextField! * secondWholeInTextField! / secondDenomInTextField!
        var fourthStep = thirdStep …
Run Code Online (Sandbox Code Playgroud)

ios swift

-1
推荐指数
1
解决办法
2865
查看次数

标签 统计

ios ×6

swift ×6

xcode ×2

nsdate ×1

nsdatepicker ×1

uiimage ×1

uiimageview ×1