I want to use auto layout for may table view cell content. This worked so far. Now I want to align a UILabel on the right side of the table view. If I do this, it isn't aligned right. Instead it is completely on the left side. So it seems the width of the table view is not calculated when the constraint is applied. I tried two different approaches:
No. 1:
this.ContentView.AddConstraints (NSLayoutConstraint.FromVisualFormat ("H:[iNumberLabel]-|", (NSLayoutFormatOptions)0, null, viewsDictionary));
No. 2:
this.ContentView.AddConstraint (NSLayoutConstraint.Create (iNumberLabel, NSLayoutAttribute.Right, NSLayoutRelation.Equal, this.ContentView, NSLayoutAttribute.Right, 1, 0));
The constraints are added in UpdateConstraints in my table view cell subclass. The code is in C# but that doesn't matter. I would be glad if you could provide a solution.
This format string: "H:|-[iNumberLabel]-|"
tells the system to pin the label to both sides of the cell with the default padding, so the label will be nearly the width of the cell. You should get rid of the spacing to the left side, if you want it right aligned,
"H:[iNumberLabel]-|"
I don't know why the second method didn't work. If that's the only horizontal constraint that you had, it should have worked.
In addition to pinning it to the right side with:
"H:[iNumberLabel]-|"
You should also rightAlight the text with:
cell.textLabel.textAlignment = NSTextAlignmentRight;
Edit: Only working for iOS 8. Currently no solution for iOS 7.
This was the culprit
this.ContentView.TranslatesAutoresizingMaskIntoConstraints = false;
I had this set when I created and added my labels as subview. When this is turned off the width of the cell seems to not get correctly laid out. Perhaps one has to add some additional constraints for the ContentView, but I don't know which (content view to super view?).
Auto resizing mask has to be enabled for the content view.
Related
I'm creating an iOS mobile application using Xamarin. I'm new in mobile development, especially on iOS. I have a table view rows, that have background images. So when I'm changing the iphone version from 5s to 6S, they are stretching. I need them to be auto resizable.
First one is my table view , the second one is the detail view of current row.
Can someone help me with this and at least tell a good topic to read.
Thanks before hands.
Here's what I have now , and I just can't remove that left offset that each row has.
First, you have to set the constraints on your UIImaveView to set the size and the position of your view.
Then, you have to set your UIImageView's Content Mode to Scale To Fill in order to have the image resized automaticaly.
You can take a look at this post to understand all Content Mode available.
I am new to Unity.
I am converting my Sudoku game written in WPF to Unity2D. I converted everything. However I cant achieve 9*9 grid with Buttons as I did in WPF.
In WPF I created 81 buttons with same event. So when it is called I jsut got their position displayed keyboard with only numbers that cell allowed.
Here is what I needed
Here is what I did.
1: I inserted canvas then tried vertical layout(for adding 3 rows) without success
2: Then I tried grid layout with canvas with fixable count column no success
3: grid layout with flexible option still no result.
I also tried via coding using GUI.BOX, and all still the result is not good.
How can I do it?
Do not use GridLayout, it is only for fixed size "icons" - irrelevant here, do not use.
First use VerticalLayoutGroup
include ..
Don't forget you must put a LayoutElement on each of your three items.
Get that working first.
Then, for your MIDDLE item, add a horizontal group and make that work.
How does one set the alignment of text within a chart legend object? I've tried using:
myChartName.Legends["mySeriesName"].Alignment = stringAlignment.Near
With no effect. I've also tried to create custom legend items, again resulting in no effect. Text is ALWAYS centered (along with the series marker) in the legend "box". The only text I have been able to align is the title, but I don't need titles in my application.
My research to date says the legend object is basically a table with (by default) two cells. If that is the case there should be a way to access those cells and manipulate them as table cells. So, what gives? Why can't I access the text alignment properties of the legend object? Clearly, there is something I'm missing, but for the life of me I can't seem to figure this out. Quite frustrating.
Problem solved. The CustomItem approach wasn't working either, so I tried using the LegendCellColumn Class.
I changed the LegendStyle from Column to Row, then added two CellColumns, one for the series symbol and one for the legend text. Set the alignment, margins, and column widths (that turned out to be the trick), and voila; a legend that looks like I want. Here's the code for anyone with a similar issue.
chartSel.Legends[ySeries.Name].CellColumns.Add(new LegendCellColumn("", LegendCellColumnType.SeriesSymbol, ""));
chartSel.Legends[ySeries.Name].CellColumns[0].Alignment = ContentAlignment.TopLeft;
chartSel.Legends[ySeries.Name].CellColumns[0].Margins = new System.Windows.Forms.DataVisualization.Charting.Margins(0, 0, 1, 1);
chartSel.Legends[ySeries.Name].CellColumns[0].MinimumWidth = 250;
chartSel.Legends[ySeries.Name].CellColumns[0].MaximumWidth = 250;
chartSel.Legends[ySeries.Name].CellColumns.Add(new LegendCellColumn("", LegendCellColumnType.Text, ySeries.Name));
chartSel.Legends[ySeries.Name].CellColumns[1].Alignment = ContentAlignment.MiddleLeft;
chartSel.Legends[ySeries.Name].CellColumns[1].Margins = new System.Windows.Forms.DataVisualization.Charting.Margins(0, 0, 1, 1);
chartSel.Legends[ySeries.Name].CellColumns[1].MinimumWidth = 1500;
chartSel.Legends[ySeries.Name].CellColumns[1].MaximumWidth = 1500;
It's probably not the most efficient way to do it, but it works. Technically, the legend symbol and text are still centered in the object, but because I'm forcing the widths of the two columns it has the appearance of being left-justified.
Hopefully, this may help another newbie like me avoid days of consternation.
My understanding is that Legend alignment relates to the Docking property, not really how the text is aligned within the legend. So setting Alignment to Near means positioning the legend box near the Docking direction.
It is quite hard to explain this textually. The MS Chart Samples have a subsection named Chart features -> Legends -> Style and Auto Positioning which will help you play with those two properties and understand how they are meant to work.
For inner legend alignment, you may need to use Legend.CustomItems and define LegendCell individually.
chart.Legends["Default"].CustomItems.Clear();
chart.Legends["Default"].CustomItems.Add(new LegendItem("LegendItem", Color.Red, ""));
chart.Legends["Default"].CustomItems[0].Cells.Add(new LegendCell(LegendCellType.Text, "My text", ContentAlignment.MiddleLeft));
This is described inside the Chart features -> Legends -> Legend Cells section of the samples.
While continuing to try to figure this out I stumbled on this tidbit of info from the following MSDN library page:
http://msdn.microsoft.com/en-us/library/dd456711(v=vs.100).aspx
"NOTE: You cannot adjust the individual legend items and cells in the Chart.Legends collection. To adjust them, use custom legend items."
So, back to the CustomItem route. I've got this code gleaned from several sources (including you, Dominique, thanks):
chartSel.Legends.Add(ySeries.Name);
chartSel.Series[ySeries.Name].IsVisibleInLegend = false;
chartSel.Legends[ySeries.Name].CustomItems.Clear();
LegendItem li = new LegendItem();
li.ImageStyle = LegendImageStyle.Line;
li.Cells.Add(LegendCellType.SeriesSymbol, "", ContentAlignment.TopLeft);
li.Cells[0].BackColor = Color.CornflowerBlue; //color is only to see the cell bounds
li.Cells.Add(LegendCellType.Text, ySeries.Name, ContentAlignment.TopLeft);
li.Cells[1].BackColor = Color.Aquamarine; //color is only to see the cell bounds
chartSel.Legends[ySeries.Name].CustomItems.Add(li);
From what I can find it should work, but it doesn't. It results in a legend object with two cells; the first is empty and the second has left-justified text. I tried to post an image of it, but the system says I'm not yet worthy.
Why there is no line for the series symbol is also a mystery, but that's another problem to solve. The text justification issue is my main concern at the moment. It looks like the text within the cells is left-justified as desired, but the cells themselves are centered in the legend object; not what I wanted. I want those cells to be left-justified in the object too, so the first cell is against the left edge of the legend object.
Ideas?
I have a WPF DataGrid and the row headers don't line up vertically with the content. Any idea why?
Seems like the RowHeaders default to VerticalAlignment = Center and TextBlock defaults to Top. They are still a little off from one another but once I changed that property it was close enough for me!
Have you tried making the row height to lets say double of it's current size? It might point you that you have different alignment/padding properties set for them :) Just a suggestion tho :) And yeah, code would be helpful :)
I believe by default the row headers are aligned like that. You should be able to tell what alignment you want by saying something like:
yourDataDrid.RowHeaderStyle.BasedOn = yourDataDrid.CellStyle;
I am trying to right align a control in a StatusStrip. How can I do that?
I don't see a property to set on ToolStripItem controls that specifies their physical alignment on the parent StatusStrip.
How do I get Messages drop down to be right aligned? http://i.friendfeed.com/ed90b205f64099687db30553daa79d075f280b90
Found it via MSDN forums almost immediately after posting :)
You can use a ToolStripLabel to pseudo right align controls by setting the Text property to string.Empty and setting the Spring property to true. This will cause it to fill all of the available space and push all the controls to the right of the ToolStripLabel over.
For me it took two simple steps:
Set MyRightIntendedToolStripItem.Alignment to Right
Set MyStatusStrip.LayoutStyle to HorizontalStackWithOverflow
As an added note this is due to the fact that in the Win32 API a cell is either fixed width or fills the remaining space -1
int statwidths[] = {100, -1};
SendMessage(hStatus, SB_SETPARTS, sizeof(statwidths)/sizeof(int), (LPARAM)statwidths);
SendMessage(hStatus, SB_SETTEXT, 0, (LPARAM)"Hi there :)");
If memory serves me correctly you can have only one fill cell (-1) per statusbar.
You could also add a third middle cell and give this the fill property to get a more concistent looking StatusBar. Consistent because Messages has an inset to its left right where you'd expect it. A bit like the mspaint shot found on the MSDN page for StatusBars
I like the creative appreach though :D
You can display the Button at the end of the StatusStrip by using the logic below.
Add a ToolstripLabel to the StatusStrip
Set text as string.Empty
Set Padding for the ToolstripLabel
For example:
this.toolStripStatusLabel1.Padding = new Padding((int)(this.Size.Width - 75), 0, 0, 0);
Keep a Toolstrip label , set Spring property as true and for label align text in BottomLeft
I found that you can set the StatusStrip Layout to HorizontalStackWithOverflow.
Then, for each control on the StatusStrip that you want on the right side, set the control Alignment to Right.
I like this better since you don't need any extra or dummy controls to align.
If you set a status strip label control’s Spring property to true, then that label takes up any space not used by other controls in the StatusStrip.
Set the RightToLeft tool strip property to True.