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
Related
I have a scrollable text frame that scrolls properly, however, the scrollbar is not visible and im not sure why. I think it is because of the way im doing the scrollbar.pack but im not sure how to change it to get it to appear properly.
helpWin = Toplevel(root)
helpWin.title('')
helpWin.geometry("650x375")
helpWin.resizable(False, False)
helpFrame = Frame(helpWin)
helpFrame.place(x = 0, y = 0)
scrollbar = Scrollbar(helpFrame, orient = VERTICAL)
help_area = Text(helpFrame, wrap = Tkinter.WORD, font=('Georgia', 8), bg=bgColor, fg='black', yscrollcommand = scrollbar.set)
scrollbar.config(command = help_area.yview)
scrollbar.pack(side = 'right', fill = "y")
help_area.pack(side = "left", fill = "y", padx = (10,0), pady = 15)
Output Window:
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
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)
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)
A chart on a form I created has two overlapping areas. The overlapping part works just fine. The problem is that visible graph only takes up half the height of the chart control:
The bottom half of the control is left empty (presumably because that's where the second area would have gone were the two areas not aligned?). I can't figure out how to get the chart to use the entire control. The code is below:
chart1.Dock = DockStyle.Fill;
chart1.Legends.Add(new Legend { Name = "Legend1" });
chart1.Location = new Point(435, 3);
chart1.Name = "chart1";
chart1.Size = new Size(426, 287);
chart1.TabIndex = 2;
chart1.Text = "chart1";
var firstArea = chart1.ChartAreas.Add("First Area");
var seriesFirst = chart1.Series.Add("First Series");
seriesFirst.ChartType = SeriesChartType.Line;
seriesFirst.Points.Add(new DataPoint(10, 55));
seriesFirst.Points.Add(new DataPoint(11, 56));
seriesFirst.Points.Add(new DataPoint(12, 59));
var secondArea = chart1.ChartAreas.Add("Second Area");
secondArea.BackColor = Color.Transparent;
secondArea.AlignmentOrientation = AreaAlignmentOrientations.All;
secondArea.AlignmentStyle = AreaAlignmentStyles.All;
secondArea.AlignWithChartArea = firstArea.Name;
secondArea.AxisY.LabelStyle.Enabled = false;
secondArea.AxisX.LabelStyle.Enabled = false;
var seriesSecond = chart1.Series.Add("Second Series");
seriesSecond.ChartType = SeriesChartType.Line;
seriesSecond.ChartArea = secondArea.Name;
seriesSecond.Points.Add(new DataPoint(10, 1001));
seriesSecond.Points.Add(new DataPoint(11, 1015));
seriesSecond.Points.Add(new DataPoint(12, 1016));
This is some old code I've dug out and modified to suit your example. The problem is the InnerPlotPosition.Auto and Position.Auto status of the ChartAreas, thats why after you add the second chart the first charts auto position jumps up and then the second chart aligns with the new InnerPlotPosition.Auto values.
You can try turning this off but I think its easier to just position the first chart manually and then allow the second to align with the new manual position. It produces the below image (minus your legend you can work the values needed yourself)
Bit of pain in the ass solution but hopefully it helps
Dim chart1 As New Chart
Me.Controls.Add(chart1)
chart1.Location = New Point(435, 3)
chart1.Name = "chart1"
chart1.Size = New Size(426, 287)
chart1.TabIndex = 2
chart1.Text = "chart1"
Dim firstArea As ChartArea = chart1.ChartAreas.Add("First Area")
Dim seriesFirst = chart1.Series.Add("First Series")
seriesFirst.ChartType = SeriesChartType.Line
seriesFirst.Points.Add(New DataPoint(10, 55))
seriesFirst.Points.Add(New DataPoint(11, 56))
seriesFirst.Points.Add(New DataPoint(12, 59))
Dim secondArea As ChartArea = chart1.ChartAreas.Add("Second Area")
secondArea.BackColor = Color.Transparent
secondArea.AlignmentOrientation = AreaAlignmentOrientations.All
secondArea.AlignmentStyle = AreaAlignmentStyles.All
secondArea.AlignWithChartArea = firstArea.Name
secondArea.AxisY.LabelStyle.Enabled = False
secondArea.AxisX.LabelStyle.Enabled = False
Dim seriesSecond = chart1.Series.Add("Second Series")
seriesSecond.ChartType = SeriesChartType.Line
seriesSecond.ChartArea = secondArea.Name
seriesSecond.Points.Add(New DataPoint(10, 1001))
seriesSecond.Points.Add(New DataPoint(11, 1015))
seriesSecond.Points.Add(New DataPoint(12, 1016))
' *** Set locational values here for your first chart***
Dim heightAboveChartArea As Integer = 20
Dim heightBelowChartArea As Integer = 20
Dim axisLabelHeight As Integer = 40
Dim widthLeftOfChartArea As Integer = 20
Dim widthRightOfChartArea As Integer = 20
Dim heightPerBar As Integer = 20
Dim numberOfPoints As Integer = chart1.Series(0).Points.Count
' *** The following code should not normally be modified ***
chart1.Height = heightAboveChartArea + heightBelowChartArea + axisLabelHeight + (numberOfPoints * heightPerBar)
chart1.ChartAreas(0).Position.X = widthLeftOfChartArea / chart1.Width * 100
chart1.ChartAreas(0).Position.Width = 100 - (widthRightOfChartArea / chart1.Width * 100) - chart1.ChartAreas(0).Position.X
chart1.ChartAreas(0).Position.Y = (heightAboveChartArea / chart1.Height * 100)
chart1.ChartAreas(0).Position.Height = 100 - (heightBelowChartArea / chart1.Height * 100) - chart1.ChartAreas(0).Position.Y
I thought about monkeying with the position, but I'd have to take into account borders and the legend and other chart components and assumed I'd never get it as good as the auto-positioning provided by the chart - and it would drive me nuts. However, the suggestion by TylerDurden led me to the idea of simply delaying the addition of the second series/area until after the chart had rendered at least once and had calculated the position. This turned out to be non-trivial, since for most of the chart's initialization the X, Y, Height and Width are still zero. The best way I found was to add the second series in the Form's Shown event:
private void OnShown(object sender, EventArgs eventArgs)
{
Application.DoEvents();
var f = chart1.ChartAreas[0].Position.ToRectangleF();
chart1.ChartAreas[0].Position.Auto = false;
chart1.ChartAreas[0].Position.X = f.X;
chart1.ChartAreas[0].Position.Y = f.Y;
chart1.ChartAreas[0].Position.Height = f.Height;
chart1.ChartAreas[0].Position.Width = f.Width;
// add second area/series here
The call to Application.DoEvents() is required to force the chart to render and calculate the Position. Since Position is a percentage, both chart areas will always occupy the full height and width of the parent Chart.