小编Tri*_*ton的帖子

在"Swift 3"中将文本从文本文件传递到UITextView

我是iOS开发的初学者,我正在尝试创建一个简单的应用程序,它将文本从文本文件传递到"Swift 3"中的UITextView.我在YouTube,堆栈和其他网站上查找过很多教程,但是所有这些教程似乎都给了我很多错误,或者对我来说太难理解了(因为我太没经验了).

Storyboard的屏幕截图

有三个按钮,三个文本文件和一个文本视图.当用户单击第一个按钮时,file1将被加载到文本字段中.

我的一些尝试,它在txt_view.text = txt1.txt上给我错误

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var txt_view: UITextView!

    @IBAction func btn_txt1(_ sender: Any) {

        txt_view.text = txt1.txt
    }

    @IBAction func btn_txt2(_ sender: Any) {

        txt_view.text = txt2.txt
    }

    @IBAction func btn_txt3(_ sender: Any) {

        txt_view.text = txt3.txt
    }

    override func viewDidLoad(){
        super.viewDidLoad()
    }

    override func didReceiveMemoryWarning(){
        super.didReceiveMemoryWarning()
    }
}
Run Code Online (Sandbox Code Playgroud)

text-files ios swift

6
推荐指数
1
解决办法
2015
查看次数

领域对象返回nil(Swift)

我有一个自定义的多边形对象,所以我可以将地图叠加保存到Realm.我能够成功创建这个对象,但是当我想要检索var多边形对象时,它返回nil.当我打印多边形对象时,它会将所有数据打印出来.

这是它打印出来的样本.

CustomPolygon {
    name = Polygon1;
    id = p1;
    polygon = Polygon {
        coordinates = RLMArray <0x7f928ef36230> (
            [0] Coordinate {
                latitude = -36.914167;
                longitude = 174.904722;
            },
            [1] Coordinate {
                latitude = -36.9325;
                longitude = 174.957222;
            }, . . . 
        );
    };
}
Run Code Online (Sandbox Code Playgroud)

我的函数从Realm加载数据

func loadOverlaysFromRealm(){

    do {

        let realm = try Realm()

        let polygons = realm.objects(CustomPolygon)

        for p in polygons {

            var coordinates = [CLLocationCoordinate2D]()

            print(p) // !!!!! prints out what is above
            print(p.polygon) // !!!!! Returns …
Run Code Online (Sandbox Code Playgroud)

arrays realm mkpolygon cllocationcoordinate2d swift

5
推荐指数
1
解决办法
3403
查看次数

UIButton Swift上的多行标签

我一直在尝试显示一个同步按钮Last Sync at (time&date)。但是我所得到的只是一行缩短的文字。

// Sync Button

syncBtn.frame = CGRectMake(15, height-60, 120, 40)

syncBtn.addTarget(self, action: "syncBtnPressed", forControlEvents: UIControlEvents.TouchUpInside)

syncBtn.setTitle("Last Sync: Never", forState: UIControlState.Normal)

syncBtn.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)

syncBtn.layer.borderColor = UIColor.whiteColor().CGColor

syncBtn.layer.borderWidth = 1

syncBtn.layer.cornerRadius = 5

syncBtn.titleLabel?.font = UIFont(name: "Avenir", size: 10)

syncBtn.alpha = 0.5

syncBtn.titleLabel?.sizeToFit()

syncBtn.titleLabel?.textAlignment = NSTextAlignment.Center

syncBtn.titleLabel?.numberOfLines = 2

self.view.addSubview(syncBtn)
Run Code Online (Sandbox Code Playgroud)

这是获取和设置标签上日期的功能

func printTimestamp(){
    var timestamp = NSDateFormatter.localizedStringFromDate(NSDate(), dateStyle: .ShortStyle, timeStyle: .ShortStyle)
    self.syncBtn.titleLabel?.text = ("Last Sync at: " + timestamp)
}
Run Code Online (Sandbox Code Playgroud)

任何人都可以解决这个问题?

xcode label button multiline swift

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