How to remove alpha of iconView in GoogleMaps? - swift

I know it sounds easy but by default GoogleMaps default function iconView has a default alpha of 0.9. I tried changing it to 1 but it's still the same. Any suggestion? Thanks in advance.
[EDIT]
This is my code
let cView = UIView(frame: CGRectMake(0,0,400*PT,300*PT))
let innerView = UIView(frame: CGRectMake(0,0,400*PT,190*PT))
innerView.backgroundColor = UIColor.whiteColor()
innerView.layer.cornerRadius = 3
innerView.layer.masksToBounds = true
innerView.alpha = 1
cView.addSubview(innerView)
let cIcon = UIImageView(frame: CGRectMake(0*PT, 200*PT, 90*PT, 100*PT))
cIcon.image = UIImage(named: "1.png")
cView.addSubview(cIcon)
cView.backgroundColor = UIColor.clearColor()
item.iconView = cView
[EDIT]
Added screenshot of the output
[EDIT]
Final output after the answer below

Might be a bit obvious, but can you try adding this?
item.opacity = 1

Related

Can't set the same color for background and border in UISegmentedControl

I am trying to customize my segmented control with Swift, but I have run into a problem. I set the same color (e.g. UIColor.red) for border and background, but they look different. My code is:
segmentedControl.layer.cornerRadius = 12
segmentedControl.layer.borderWidth = 2
segmentedControl.layer.borderColor = UIColor.red.cgColor
segmentedControl.layer.masksToBounds = true
segmentedControl.backgroundColor = .red
Maybe someone knows how can I fix it?
Try setting the tintColor and selectedSegmentTintColor:
segmentedControl.tintColor = .white
segmentedControl.selectedSegmentTintColor = .white

Is this a UITextView transparency bug?

This issue came up in relation to a problem I had yesterday for which I should be able to create a workaround. As I investigated further, I found that it occurs more broadly than I originally thought. I had previously only noticed it in displayed text that included at least one newline character, but that's not the case below.
The problem seems to result from using the NSLayoutManager's boundingRect method to obtain (among other things) individual character widths and then using those widths to set characters' UITextView frame width properties. Doing so apparently causes the setting of the text view's backgroundColor to UIColor.clear to be ignored (i.e., the background becomes opaque). The Playground code below reproduces the problem, shown in red text, and shows the workaround of using a constant for widths, in black. The tighter the kerning, the more pronounced the effect.
Is this a bug? Or is it a quirk due to something else?
//: A UIKit based Playground for presenting user interface
import UIKit
import PlaygroundSupport
class MyViewController : UIViewController {
override func loadView() {
let view = UIView()
view.bounds = CGRect(x: -100, y: -100, width: 200, height: 200)
view.backgroundColor = .white
let str = "..T.V.W.Y.."
let strStorage = NSTextStorage(string: str)
let layoutManager = NSLayoutManager()
strStorage.addLayoutManager(layoutManager)
let textContainer = NSTextContainer(size: view.bounds.size)
textContainer.lineFragmentPadding = 0.0
layoutManager.addTextContainer(textContainer)
let strArray = Array(str)
struct CharInfo {
var char: Character
var origin: CGPoint?
var size: CGSize?
}
var charInfoArray = [CharInfo]()
for index in 0..<str.count {
charInfoArray.append(CharInfo.init(char: strArray[index], origin: nil, size: nil))
let charRange = NSMakeRange(index, 1)
let charRect = layoutManager.boundingRect(forGlyphRange: charRange, in: textContainer)
charInfoArray[index].origin = charRect.origin
charInfoArray[index].size = charRect.size
}
for charInfo in charInfoArray {
let textView0 = UITextView()
textView0.backgroundColor = UIColor.clear // Ignored in this case!!
textView0.text = String(charInfo.char)
textView0.textContainerInset = UIEdgeInsets.zero
let size0 = charInfo.size!
textView0.frame = CGRect(origin: charInfo.origin!, size: size0)
textView0.textContainer.lineFragmentPadding = CGFloat(0.0)
textView0.textColor = UIColor.red
view.addSubview(textView0)
let textView1 = UITextView()
textView1.backgroundColor = UIColor.clear // Required
textView1.text = String(charInfo.char)
textView1.textContainerInset = UIEdgeInsets.zero
var size1 = charInfo.size!
size1.width = 20 // But changing .height has no effect on opacity
textView1.frame = CGRect(origin: charInfo.origin!, size: size1)
textView1.frame = textView1.frame.offsetBy(dx: 0, dy: 20)
textView1.textContainer.lineFragmentPadding = CGFloat(0.0)
textView1.textColor = UIColor.black
view.addSubview(textView1)
}
self.view = view
}
}
// Present the view controller in the Live View window
PlaygroundPage.current.liveView = MyViewController()
This does seem to be a bug, but it's with NSLayoutManager's instance method boundingRect(forGlyphRange:in:). It only looks like it could be a transparency change.
According to Apple's documentation, boundingRect(forGlyphRange:in:) is supposed to "[return] a single bounding rectangle (in container coordinates) enclosing all glyphs and other marks drawn in the given text container for the given glyph range, including glyphs that draw outside their line fragment rectangles and text attributes such as underlining." But that's not what it's doing.
In this case, the width of each boundingRect gets reduced by the amount that the next glyph was shifted to the left, due to kerning. You can test this, for example, using str = "ToT" and adding print(size0.width) right after it is set. You'll get this:
6.0 // "T"; should have been 7.330078125
6.673828125 // "o"
7.330078125 // "T"
Until this bug is fixed, a workaround would be to calculate glyph size for each character in isolation.

Swift and Visual Format Language (VFL) not happy with vertical and horizontal layout

I am trying to make a UIView that consist of 4 element:
1 x UIView
3 x UIScrollView
Layout setup
The 4 subviews works perfectly individually, however the VFL for this view has turned out to be difficult. The views are configured like this:
let frame0View = UIView()
frame0View.translatesAutoresizingMaskIntoConstraints = false
frame0View.backgroundColor = .yellow
frame0View.frame = CGRect(x: 0, y: 0, width: 80, height: 100)
let frame1ScrollView = UIScrollView()
frame1ScrollView.backgroundColor = .cyan
frame1ScrollView.translatesAutoresizingMaskIntoConstraints = false
frame1ScrollView.contentSize = frame1View.bounds.size
and the same for frame2ScrollView and 3
My expectation is the a VFL setup like this for the “superview” should work:
let mainHorizontalVFL1 = "H:|[FRAME0(80)]-[FRAME1SCROLL(>=200)]-(>=0#500)-|"
let mainHorizontalVFL2 = "H:|[FRAME2SCROLL(80)]-[FRAME3SCROLL(>=200)]-(>=0#500)-|"
let mainVerticalVFL = "V:|[FRAME0(60)]-[FRAME2SCROLL(\(numberOfPlayers*90))]-(>=1#500)-|"
However this does not work (both FRAME1SCROLL and FRAME3SCROLL is not visible at all). By accident I got the below setup to work (with the auto layout complaining about "Unable to simultaneously satisfy constraints” as expected)
let mainHorizontalVFL1 = "H:|[FRAME0(80)]-[FRAME1SCROLL(>=200)]-(>=0#500)-|"
let mainHorizontalVFL2 = "H:|[FRAME2SCROLL(80)]-[FRAME3SCROLL(>=200)]-(>=0#500)-|"
let mainVerticalVFL = "V:|[FRAME0(60)]-[FRAME1SCROLL(60)]-[FRAME2SCROLL(\(numberOfPlayers*90))]-[FRAME3SCROLL(\(numberOfPlayers*90))]-(>=0#500)-|"
This setup works for now, but it is kind of annoying that I am not able to use the expected setup. Anyone has any idea what to look for to fix this?

Adding min/max images to NSSlider using Swift

I created a NSSlider programmatically and implemented it in a NSMenuItem:
let menuVolumeSliderItem = NSMenuItem()
let menuVolumeSlider = NSSlider()
menuVolumeSlider.sliderType = NSSliderType.linear
menuVolumeSlider.isEnabled = true
menuVolumeSlider.isContinuous = true
menuVolumeSlider.action = #selector(AppDelegate.doSomething)
menuVolumeSlider.minValue = 0.0
menuVolumeSlider.maxValue = 1.0
menuVolumeSlider.floatValue = 0.5
menuVolumeSlider.frame.size.width = menu.size.width
menuVolumeSlider.frame.size.height = 20.0
menuVolumeSliderItem.view = menuVolumeSlider
menu.addItem(menuVolumeSliderItem)
And essentially, it work’s like a charm:
But the result I want to achieve is a Slider with a min/max image on the left/right edge of the Slider like this one:
How can I achieve a NSMenuItem like that?
EDIT:
I’ve created a custom NSView:
let view = NSView()
view.frame.size.width = menu.size.width
view.frame.size.height = 25.0
... then created a NSImage ...
let img = NSImageView()
img.frame.size.width = 16.0
img.frame.size.height = 16.0
img.image = NSImage(named: "NSStatusAvailable")!
... and added menuVolumeSlider and img to my custom view:
view.addSubview(img)
view.addSubview(menuVolumeSlider)
menuVolumeSliderItem.view = view
menu.addItem(menuVolumeSliderItem)
... and it worked! But can anyone please give me a hint how to change the positions of the subViews?
Create a NSView that will include the slider and the two images. Then set menuVolumeSliderItem.view to be that NSView.

SKLightNode: Changing alpha of ambientColor

Is there a way to change the alpha value of an SKLightNodes ambientColor so that e.g. their background can be seen even if the lightNode is on the other side of the screen?
//Add LightNode
let lightNode = SKLightNode()
lightNode.ambientColor = UIColor.blackColor()
lightNode.lightColor = UIColor.whiteColor()
lightNode.shadowColor = UIColor.blackColor()
lightNode.categoryBitMask = LightCategory.Light1.rawValue
lightNode.enabled = true
lightNode.falloff = 0.05
self.addChild(lightNode)
//Sprite
sprite.lightingBitMask = LightCategory.Light1.rawValue
It says here in the SKLightNode Class Reference that, "The alpha value of the color is ignored." If you want things on the other end of the screen to be visible, you should change the falloff.