UIStackView can I add it with autoresizing instead of autolayout - uiscrollview

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

Related

NSWindow animated blur & fade using CATransition and CIFilter: not working the first time?

I try to apply a blur + saturation + fade effect on an NSWindow. Basically, when opening a sheet, I want the window behind the modal sheet to become blurred first.
Strangely, I can achieve this, but always at the second animation, never the first one. I've tried various combination of addSubview & addAnimation etc, but always failed so far.
Any idea? Here is my code:
self.contentView!.wantsLayer = true
let animation = CATransition()
animation.type = kCATransitionFade
animation.duration = 0.5
self.contentView!.layer?.addAnimation(animation, forKey: "layerAnimation")
let saturationFilter = CIFilter(name: "CIColorControls")!
saturationFilter.setDefaults()
saturationFilter.setValue(2, forKey: "inputSaturation")
let blurFilter = CIFilter(name: "CIGaussianBlur")!
blurFilter.setDefaults()
blurFilter.setValue(1.5, forKey:"inputRadius")
let coverView = NSView()
coverView.frame = self.contentView!.bounds
coverView.wantsLayer = true
coverView.layerUsesCoreImageFilters = true
coverView.autoresizingMask = [.ViewWidthSizable, .ViewHeightSizable]
coverView.layer!.opaque = false
coverView.layer!.backgroundColor = NSColor(white: 0.9, alpha: 0.5).CGColor
coverView.layer!.backgroundFilters = [saturationFilter, blurFilter]
self.contentView!.addSubview(coverView)

Set borderColor to UIView

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

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

UIScrollView does not work, only one image is displayed

I am trying to create a UIScrollView - but it doesnt work. I only see one image in the view - swipe1. The scroll view does scroll forward but its blank and I dont see the other 2 images.
def create_image_scroll_view_NICE
#scroll_view = UIScrollView.alloc.initWithFrame self.view.bounds
#scroll_view.delegate = self
#scroll_view.scrollsToTop = false
self.view.addSubview #scroll_view
#scroll_view.pagingEnabled = true
#scroll_view.showsHorizontalScrollIndicator = false
#scroll_view.contentSize = CGSizeMake(NUMBER_OF_PAGES * self.view.frame.size.width, self.view.frame.size.height)
#delivery_image = UIImageView.alloc.initWithImage(UIImage.imageNamed("swipe3"))
#scroll_view.addSubview #delivery_image
#notification_image = UIImageView.alloc.initWithImage(UIImage.imageNamed("swipe2"))
#scroll_view.addSubview #notification_image
#box_image = UIImageView.alloc.initWithImage(UIImage.imageNamed("swipe1"))
#scroll_view.addSubview #box_image
end
because three images frame are same .
you need to set frame like this:
delivery_image.frame = CGRectMake(0,0,width,height);
notification_image.frame = CGRectMake(self.view.frame.size.width,0,width,height);
box_image.frame = CGRectMake(self.view.frame.size.width*2,0,width,height);
All of your imageView's are going to have an origin of [0, 0] so they will all overlap.
What you need to do is offset the frame of each image so it appears next to the previous image
%w(swipe3 swipe2 swipe1).each_with_index do |image_name, index|
delivery_image = UIImageView.alloc.initWithImage(UIImage.imageNamed(image_name))
x_offset = CGRectGetWidth(self.view.frame) * index
delivery_image.frame = [[ x_offset, 0], delivery_image.frame.size ]
#scroll_view.addSubview delivery_image
end

Win7: Set Custom Text Size changes position of button's image

Good day all! I have a very tricky for me question.
In my application I have button with image inside. All properties of this button:
Me.cmdSelectAll.BackColor = System.Drawing.SystemColors.Control
Me.cmdSelectAll.Image = CType(resources.GetObject("cmdSelectAll.BackgroundImage"), System.Drawing.Image)
Me.cmdSelectAll.ImageAlign = Drawing.ContentAlignment.BottomRight
Me.cmdSelectAll.Cursor = System.Windows.Forms.Cursors.Default
Me.cmdSelectAll.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.cmdSelectAll.ForeColor = System.Drawing.SystemColors.ControlText
Me.cmdSelectAll.Location = New System.Drawing.Point(0, 282)
Me.cmdSelectAll.Name = "cmdSelectAll"
Me.cmdSelectAll.Padding = New System.Windows.Forms.Padding(0, 0, 0, 0)
Me.cmdSelectAll.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.cmdSelectAll.Size = New System.Drawing.Size(22, 22)
Me.cmdSelectAll.TabIndex = 11
Me.cmdSelectAll.TabStop = False
Me.ToolTip1.SetToolTip(Me.cmdSelectAll, "Select All Channels")
Me.cmdSelectAll.UseVisualStyleBackColor = False
When I run it with default text size of win7, the image appears in the center, it's all ok. But when I set some custom value of text size (115%) my image suddenly goes more right and down. It occurs with all of my button's images. Could you please answer me why does this happen and how can i fix this issue? Thanks

Resources