Buttonwithtype' Is Unavailable: Use Object Construction 'Uibutton(Type:)

buttonWithType' is unavailable: use object construction 'UIButton(type:)

For Swift 3 the syntax is the following:

let button = UIButton(type: .detailDisclosure)

buttonWithType' is unavailable: use object construction 'UIButton(type:)

Just convert this

self.hintButton = UIButton.buttonWithType(.custom)

to this

self.hintButton = UIButton(type: .custom)

iOS 9 UIButton Initialization

The convenience initializer for UIButton has changed.

convenience init(type buttonType: UIButtonType)

Swift 3:

let btn = UIButton(type: .system) // note the lower case s

Swift 2.x:

let btn = UIButton(type: .System)

iOS 9 UIButton Initialization

The convenience initializer for UIButton has changed.

convenience init(type buttonType: UIButtonType)

Swift 3:

let btn = UIButton(type: .system) // note the lower case s

Swift 2.x:

let btn = UIButton(type: .System)

How to change the background color of a UIButton while it's highlighted?

You can override UIButton's setHighlighted method.

Objective-C

- (void)setHighlighted:(BOOL)highlighted {
[super setHighlighted:highlighted];

if (highlighted) {
self.backgroundColor = UIColorFromRGB(0x387038);
} else {
self.backgroundColor = UIColorFromRGB(0x5bb75b);
}
}

Swift 3.0 and Swift 4.1

override open var isHighlighted: Bool {
didSet {
backgroundColor = isHighlighted ? UIColor.black : UIColor.white
}
}

Add Text Label and Button to dynamic tableview cell programmatically with Swift

You can implement like this

let titleArray = ["a", "b", "c"]

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 50
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
//return no.of cell do you want
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cellHeight = tableView(self.tableView, heightForRowAtIndexPath: NSIndexPath(forRow: indexPath.row, inSection: indexPath.section))
var cell = CustomCell(frame: CGRectMake(0, 0, self.view.frame.width, cellHeight), title: titleArray[indexPath.row])
cell.cellLabel.text = //labelText
cell.cellButton.addTarget(self, action: "buttonPressed:", forControlEvents: UIControlEvents.TouchUpInside)

return cell
}

class CustomCell: UITableViewCell {
var cellButton: UIButton!
var cellLabel: UILabel!

init(frame: CGRect, title: String) {
super.init(style: UITableViewCellStyle.Default, reuseIdentifier: "cell")

cellLabel= UILabel(frame: CGRectMake(self.frame.width - 100, 10, 100.0, 40))
cellLabel.textColor = UIColor.blackColor()
cellLabel.font = //set font here

cellButton = UIButton(frame: CGRectMake(5, 5, 50, 30))
cellButton.setTitle(title, forState: UIControlState.Normal)

addSubview(cellLabel)
addSubview(cellButton)
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
}
}

iOS bottom align an object with programmatic auto layout constraints

Ok, so it looks like DetailView.h subclassed UIScrollView rather than UIView. Setting the proper subclass caused the constraints to operate as expected.



Related Topics



Leave a reply



Submit