IOS UITextView

来源:互联网 发布:js中怎么给input赋值 编辑:程序博客网 时间:2024/05/23 13:08


////  ViewController.swift//  UITextView////  Created by liaojianguo on 15/11/7.//  Copyright © 2015年 liaojianguo. All rights reserved.//import UIKitclass ViewController: UIViewController {    override func viewDidLoad() {        super.viewDidLoad()        // Do any additional setup after loading the view, typically from a nib.                let textViewFrame = CGRectMake(10.0,100.0,240.0,90.0);                let textView = UITextView(frame: textViewFrame)        textView.layer.borderWidth=1 //layer为层的意思,border为包边,边界的意思        textView.layer.borderColor=UIColor.grayColor().CGColor        textView.editable=true//是否可以编辑        //textView 和 UILabel一样,是继承与UIView        textView.dataDetectorTypes=UIDataDetectorTypes.All//detector为检测器,检测是否有网页、电话等进行链接        textView.layer.cornerRadius = 6//圆角        textView.layer.masksToBounds = true        textView.scrollEnabled=true//可以滚动        textView.keyboardType = UIKeyboardType.NumberPad//数字键盘        textView.layer.borderColor = UIColor(red: 60/255, green: 40/255, blue: 129/255, alpha: 1).CGColor;        textView.autoresizingMask = UIViewAutoresizing.FlexibleHeight//自动适配高度        //下面为加图片背景,网上没有找到swift语言的该组建的加图片,我是根据object-c翻译过来的,测试成功了        let image = UIImage(named:"cat.jpg")        let imageView = UIImageView(frame: textView.bounds)        imageView.image = image        textView.addSubview(imageView)        textView.sendSubviewToBack(imageView)                self.view.addSubview(textView)    }    override func didReceiveMemoryWarning() {        super.didReceiveMemoryWarning()        // Dispose of any resources that can be recreated.    }}


0 0
原创粉丝点击