2015. 8. 23.

Rounded square button in swift ( customizing shape and color in code)


override func viewDidLoad() {
        super.viewDidLoad()

     let TAG_BTN = 1001  // it is assigned to button which you want to change properties.
     let btn : UIButton  = self.view.viewWithTag(TAG_BTN) as! UIButton
     btn.layer.cornerRadius = 5
     btn.layer.borderColor = UIColor.grayColor().CGColor
     btn.layer.borderWidth = 1.5

     btn.backgroundColor = UIColor(red: 1.0, green: 0, blue: 0, alpha: 1)
}



2015. 8. 14.

Removing space of table seperator ( Drawing sperator full width)

http://www.malcontentboffin.com/2014/10/28/Make-iOS-8-Table-View-Cell-Separators-Full-Width



    override 
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
        //remove identation line ( draw full seperator.)
        cell.separatorInset = UIEdgeInsetsZero
        cell.layoutMargins = UIEdgeInsetsZero
        cell.preservesSuperviewLayoutMargins = false

    }

using image as x repeated background in swift

I found many solutions above title. but It is written in a objective-c  like that:

objView.backgroundColor = [[UIColor allocinitWithPatternImage:[UIImage imageNamed:@"background_image"]];


but in swift   it can be written like that:


 objView.backgroundColor = UIColor(patternImage: UIImage(named: "background_image")!)

2015. 8. 8.

Using UITableView in ViewController (iOS Swift)

When I make UIViewController,  I need to display list , so I think I can use UITableView in UIViewController , but I found it is not possible because of mechanism of iOS.

They provide  another way.  That is using UIContainerView.

In Storyboard,
1) Drag UIViewController
2) Drag  UIContainerView into UIViewController( step.1)
    segue and default view controller will be created.
3) Drag UITableViewController  ( not UITableView)
4) delete segue and default view controller (step.2)
5) Link container  to UITableViewController (step.3)
     - (how to link?: click container with control key and drag to UITableViewController)

** Additional step
    If you have a existing segue with other viewcontroller, you may meet error. So you must check segue.identifier.