Set borderColor to UIView - xcode

Is there any possible ways i can set a border color on a UI View?
I have tried this, but it does not work:
newView.backgroundColor = UIColor.clearColor()
newView.layer.cornerRadius = 2
newView.layer.borderWidth = 1
newView.layer.borderColor = UIColor.redColor().CGColor

Actually now this made it work:
newView.layer.borderColor = UIColor.redColor().CGColor
newView.layer.cornerRadius = 5
newView.layer.borderWidth = 2

Related

How to change the color of the dot inside a radio button with Resource Hacker

I’m trying to modify the color of the dot inside a radio button with Resource Hacker. I managed to change the color of the circle/frame but not the dot inside. I looked everywhere online and found similar examples but doesn’t exactly suit me with my situation. I guess all I need is the right syntax format. I tried so many different code combinations to no avail since I’m a newbie in coding. I’d really appreciate if you could help me out. The exact code I’m fiddling is below. Many thanks in advance.
object ScanCandidateGrp: TRzRadioGroup
Left = 103
Top = 34
Width = 64
Height = 66
Font.Charset = ANSI_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'Tahoma'
Font.Style = []
TextShadowColor = clActiveBorder
GroupStyle = gsCustom
ItemFrameColor = clRed << I managed to change the circle color with this
ItemHotTrack = True
ItemHighlightColor = clBlue
ItemHotTrackColor = clGreen
ItemIndex = 0
Items.Strings = (
'Bob'
'Alex'
'Sue')
ParentFont = False
StartXPos = 2
StartYPos = 0
TabOrder = 0
Transparent = True
VerticalSpacing = 5
OnClick = ScanCandidateGrpClick
end

UIStackView can I add it with autoresizing instead of autolayout

I've tried to place UIStackView inside UIScrollView with autoresizing masks .flexibleWidth, .flexibleHeight -> i.e. stretch horizontally/vertically to fill scroll view but stack view does not appear if I changed this to autolayout code with leading/trailing/bottom/top constraints then views appear correctly
toolbar.autoresizingMask = [.flexibleWidth, .flexibleHeight]
toolbar.backgroundColor = .clear
toolbar.axis = .horizontal
toolbar.distribution = .fill
toolbar.alignment = .fill
toolbar.spacing = 8
toolbarScroll.frame = bounds
toolbarScroll.autoresizingMask = [.flexibleHeight, .flexibleWidth]
toolbarScroll.showsHorizontalScrollIndicator = false
toolbarScroll.showsVerticalScrollIndicator = false
toolbarScroll.backgroundColor = UIColor.green
toolbarScroll.addSubview(toolbar)
Here is code that if added after addSubview then toolbar show in toolbarScroll
toolbar.translatesAutoresizingMaskIntoConstraints = false
toolbar.leadingAnchor.constraint(equalTo: toolbarScroll.leadingAnchor).isActive = true
toolbar.trailingAnchor.constraint(equalTo: toolbarScroll.trailingAnchor).isActive = true
toolbar.bottomAnchor.constraint(equalTo: toolbarScroll.bottomAnchor).isActive = true
toolbar.topAnchor.constraint(equalTo: toolbarScroll.topAnchor).isActive = true
You added toolbar to toolbarScroll, but you didn't give it a frame.
toolbarScroll.addSubview(toolbar)
// just to make sure...
toolbar.translatesAutoresizingMaskIntoConstraints = true
// give the toolbar stackView a frame
toolbar.frame = toolbarScroll.bounds

Swift Code Improvement

I'm quite new to Swift and Xcode 6 and just made an app. Now I'm trying to improve my code and I know there's a way to make this code way shorter, I just don't know how.
button1.layer.cornerRadius = 10
button1.layer.borderWidth = 1
button1.layer.borderColor = UIColor.whiteColor().CGColor
button2.layer.cornerRadius = 10
button2.layer.borderWidth = 1
button2.layer.borderColor = UIColor.whiteColor().CGColor
button3.layer.cornerRadius = 10
button3.layer.borderWidth = 1
button3.layer.borderColor = UIColor.whiteColor().CGColor
button4.layer.cornerRadius = 10
button4.layer.borderWidth = 1
button4.layer.borderColor = UIColor.whiteColor().CGColor
button5.layer.cornerRadius = 10
button5.layer.borderWidth = 1
button5.layer.borderColor = UIColor.whiteColor().CGColor
You can create an array of all the buttons, and then loop through them.
var buttons = [button1, button2, button3, button4, button5]
for button in buttons {
button.layer.cornerRadius = 10
button.layer.borderWidth = 1
button.layer.borderColor = UIColor.whiteColor().CGColor
}

Spritekit Swift particle SKEmitterNode add remove

so this is nice for create a particle, but whats the right way to remove it , after the duration, sparkEmmiter.particleLifetime do not remove it automatically
let sparkEmmiter = SKEmitterNode(fileNamed: "MyParticle.sks")
sparkEmmiter.position = CGPointMake(self.frame.size.width/2, self.frame.size.height/2 - 200)
sparkEmmiter.name = "sparkEmmitter"
sparkEmmiter.zPosition = 1
sparkEmmiter.targetNode = self
sparkEmmiter.particleLifetime = 1
self.addChild(sparkEmmiter)
this solutions produce simulator crash
var re = SKAction.waitForDuration(1)
var remove = SKAction.removeFromParent()
var seq = SKAction.sequence([re , remove])
sparkEmmiter.runAction(seq)

Creating UI element won't let change position

I tried this:
#IBAction func test(sender : AnyObject){
let height:CGFloat = 44
var tableFrame:CGRect = tableView.frame;
var fieldFrame = CGRect()
fieldFrame.origin = tableFrame.origin
fieldFrame.size.height = height
fieldFrame.size.width = tableFrame.size.width
var textField = UITextField(frame: fieldFrame)
textField.backgroundColor = UIColor(white: 0, alpha: 1)
view.addSubview(textField)
tableFrame.size.height = tableFrame.size.height - height
tableFrame.origin.y = tableFrame.origin.y + height
tableView.frame = tableFrame
}
When running, black field appears, but table won't move nor change size. Removing line
view.addSubview(textField)
allows table to change size and move, but, obviously, no field appears. What is the problem?
your textfield is actually on top of tableview. Your touch actions are probably going to the text fieldview and not to the tableview

Resources