I set my image works well like this:
self.avatarImageView.image = self.avatarImage
But, when i want to change it to circle in this way the image disappear.
self.avatarImageView.layer.masksToBounds = true
self.avatarImageView.image = self.avatarImage
self.avatarImageView.layer.cornerRadius = self.avatarImageView.frame.width/2
Add this line to layout it works.
self.avatarImageView.layoutIfNeeded()
Related
UPDATE: Solved! While the contentMode for pianoNoteDisplayed and piano_background were indeed the same, apparently this wasn't true for the added subviews. I simply added the line subview.contentMode = superview.contentMode to the function vdmzz suggested, and now everything looks right on all 4 screen sizes.
There are two image views: one called "piano_background" holds a background image (a piano keyboard) and the other will be used to display highlighted notes. The second is constrained to the first:
(the width constraint is probably unnecessary, because the leading and trailing constraints are already set, right?)
To display multiple highlighted keys, I am programmatically adding subviews to the piano_note view and activating the NSLayoutConstraints to get it into place (otherwise it shows up way out of position) like so:
pianoNoteDisplayed.image = nil
if !notesAlreadyAttempted.contains(currentUserAnswer) {
let wrongNoteImageName = "large_\(currentUserAnswer)_wrong"
let wrongNoteImage = UIImage(named: wrongNoteImageName)
let wrongNoteImageView = UIImageView(image: wrongNoteImage!)
wrongNoteImageView.translatesAutoresizingMaskIntoConstraints = false
pianoNoteDisplayed.addSubview(wrongNoteImageView)
NSLayoutConstraint.activate([
wrongNoteImageView.widthAnchor.constraint(equalToConstant: pianoNoteDisplayed!.frame.width),
wrongNoteImageView.heightAnchor.constraint(equalToConstant: pianoNoteDisplayed!.frame.height)
])
}
notesAlreadyAttempted.append(currentUserAnswer)
}
The issue is that the subview is displayed slightly off, and I can't seem to figure out why:
(as you can see, the highlight looks slightly compressed vertically.. the top lands correctly, but the bottom doesn't reach far enough by about 5px)
I have tried centering and constraining the subview in multiple ways, using suggestions from about 5 different answers on stack, and a few other articles I found. The images I am using (the piano background and the overlaying note highlight subview) are identical sizes. I have tried adding more or fewer constraints in the interface builder, and I have tried adding subviews to the original piano_background view instead of the second pianoNoteDisplayed view - same result. Using the pianoNoteDisplayed view itself to display the highlighted note works fine by the way:
And these are displayed using the usual .image method:
pianoNoteDisplayed.image = UIImage(named: "large_\(currentCorrectAnswer)_right")
Any suggestions for how to troubleshoot the issue further?
First of all, as far as I understood pianoNoteDisplayed doesn't need to be an UIImageView.
Secondly, if you align piano_background and pianoNoteDisplayed by top, leading, trailing and bottom edges, one will be exactly on top of other. Or you could set them equal height, width and center positions.
The problem with your current set of constraints is that piano_background's Y position is determined by Safe Area and therefore might defer from pianoNoteDisplayed's Y position.
Try using this function:
func addSameSize(subview: UIView, onTopOf superview: UIView) {
superview.addSubview(subview)
subview.translatesAutoresizingMaskIntoConstraints = false
subview.centerXAnchor.constraint(equalTo: superview.centerXAnchor).isActive = true
subview.centerYAnchor.constraint(equalTo: superview.centerYAnchor).isActive = true
subview.widthAnchor.constraint(equalTo: superview.widthAnchor).isActive = true
subview.heightAnchor.constraint(equalTo: superview.heightAnchor).isActive = true
subview.contentMode = superview.contentMode
}
E.g.
addSameSize(subview: wrongNoteImageView, onTopOf: pianoNoteDisplayed)
It will add your image views exactly aligned on top of pianoNoteDisplayed view
I'm using a Bar Chart that I'm trying to make look like a design. The design's bars overflow a bit at the bottom and have a transparency gradient on them. I can't find any property that you can use for this and I guess I'll have to override somewhere. I've also tried to draw layers on top of the graph at the bars positions/bounds without success.
I tried overriding the BarChartRenderer and change the Y-positions, but since the graph is supposed to be "scrollable" by default it clips the bar.
I've already disabled the scrolling/moving/zooming functions because I don't need them:
doubleTapToZoomEnabled = false
highlightPerDragEnabled = false
highlightPerTapEnabled = false
clipValuesToContentEnabled = false
You can set the minimum axis value so that it set the bottom line correct try this code as
barChartView.leftAxis.axisMinimum = __Your minimum bar value__ i.e. 17000 //that is mention in your above graph
Solved it by drawing my own layers over the bars and then remove the old bars because of their anti-aliasing. This way it will be easier to implement the gradient too, and it works because you won't be able to move/scale the chart.
let bottomY = self.contentRect.maxY - leftAxis.gridLineWidth
for (_, bar) in self.barData!.dataSets.enumerated() {
let layer = CALayer(),
barBounds = self.getBarBounds(entry: bar.entryForIndex(0)! as! BarChartDataEntry),
// 30 extra height at bottom
frame = CGRect(x: barBounds.minX, y: barBounds.minY, width: barBounds.width, height: (bottomY - barBounds.minY) + 30)
// Set the new frame size, Z position and background
layer.frame = frame
layer.zPosition = 10
layer.backgroundColor = bar.color(atIndex: 0).cgColor
// Add the new bar layer and remove old bar
self.layer.addSublayer(layer)
bar.clear()
}
I want to set exterior app's frame from my own project and I found a problem:
I can set its size and its position (but the thing is, I want it to be full screen, and even if I set the size to be full screen it does not set it's size to it (I have to press the button several times).
I think the problem is with its frame.
var frame = CGRectMake(0.0, 23.0, 1280.0, 770.0) //I post only this as size and position seem to work
let sizeCoo: AXValue = AXValueCreate(AXValueType(rawValue: kAXValueCGSizeType)!, &size)!.takeRetainedValue()
let positionCoo: AXValue = AXValueCreate(AXValueType(rawValue: kAXValueCGPointType)!, &position)!.takeRetainedValue()
let frameCoo: AXValue = AXValueCreate(AXValueType(rawValue: kAXValueCGRectType)!, &frame)!.takeRetainedValue()
let errorFrame = AXUIElementSetAttributeValue(myApp, "AXFrame", frameCoo)
Setting sizeCoo and positionCoo give me an error with raw value = 0 - everythng is ok, but setting frameCoo displays an error with rawValue = -25205 which means:
/*! The attribute is not supported by the AXUIElementRef. */
kAXErrorAttributeUnsupported = -25205
and I clearly see when I list attributes for this window there is the "AXFrame" attribute.
What am I doing wrong?
I load images via LoadQueue:
this.queue = new createjs.LoadQueue(false);
I create my bitmap, this works fine:
var myImg = new createjs.Bitmap(this.queue.getResult('test-img'));
myImg.scaleX = 0.2;
myImg.scaleY = 0.2;
myImg.x = 300;
I then add a blur:
var blurFilter = new createjs.BlurFilter(5, 5, 1);
myImg.filters = [blurFilter];
var bounds = blurFilter.getBounds();
myImg.cache(-50+bounds.x, -50+bounds.y, 100+bounds.width, 100+bounds.height);
Then finish up with:
this.stage.addChild(myImg);
this.stage.update();
The problem is, as soon as I add the blur, the image no longer appears, where am I going wrong?
I implemented your code and it works well http://jsfiddle.net/k4yhz6oy/2/.
I suppose the cache area of your image is white or transparent.
myImg.cache(-50+bounds.x, -50+bounds.y, 100+bounds.width, 100+bounds.height);
Apply image bounds to cache
var imageBound = myImg.getBounds();
myImg.cache(imageBound.x, imageBound.y, imageBound.width, imageBound.height);
I downloaded JDFlipNumberView from here.
It works but there is a problem with the frame. To change the frame the developer has said to use:
flipNumberView.frame = CGRectMake(10,100,300,100);
but when I do this it doesn't change.
PS: when I put NSLog(#"%#",flipNumberView.frame); it returns null.
How can I change the frame?
"fram' is not a string, it is structure's object.so if you want see frame. you can use it.
NSLog(#"Width = %f",btn.frame.size.width);
NSLog(#"height = %f",btn.frame.size.height);
NSLog(#"x = %f",btn.frame.origin.x);
NSLog(#"y = %f",btn.frame.origin.y);
may be it help for you.
If you use the example project, you need to deactivate the layoutSubviews: method first. It resets the frame on every relayout.
Otherwise just set a new frame.