Method to display UILabels and UIButtons Inline with each Other - ios

In my app I have a "summary" paragraph that based on data an user actions in the app changes what it displays. The issue is it displays both regular text and clickable text (like a button) in the same sentence and line. The app will have a series of if else statements and based on the results of these the text that will be displayed is determined, but how do you make some of the text a button tied to an action and some of the text a plain label? Any and all help is appreciated!

In iOS 7, buttons look like blue text. I would suggest taking advantage of that fact.
I would use AutoLayout, and create your fields with constraints that put a very small amount of space between each label and button in your line of text/labels, with a vertical constraint on all of them that aligns their leading to match.

Related

Swift UIButton edge insets

I am trying to make a square button that is on the smaller side (30x30), and I want to include the amount of participants there are as the text, for some reason the button is cutting the title off on the left and ride sides (see picture) forcing me to either have a bigger button (not ideal) or have really small text (also not ideal). Is there a way to stop it from cutting off?
If you're trying to display one character in that 30*30 button, make the button size large, check screenshots for reference:
Change Button Style Plain into Default.

How can I style a text field in iOS (Swift)?

I am a beginner and just started learning iOS. I want to achieve this layout, using Swift:
When you drag a text field into your project, there's a number of styling options available in the Utilities bar in Xcode, that can help you style the shape, colour and other properties of your field. To achieve the look you want, you could use something like this:
Place a UITextField and a UIButton on your story board. Then select both items, and then go to Editor, Embed In, stack view. If they are one on top of the other, change the stack view orientation to vertical then they will be side by side as shown above. Next change the attributes of both in the attributes inspector to taste. You can change the attributes manually in code using textField.defaultTextAttrubutes = [ "the look you are going for"], but you should need to in order to recreate your example.
you can add a view container to your view, inside that container .. add a button and a textfield then add positioning constraints on them.
as you can see in the picture .. it illustrates the idea .. you can style it the way you want e.g. change the height of your textfield .. change its border style etc. the same with your button.
example
In order to add a border, you have to enter some specific information in the attributes inspector. Here is a snapshot of what you can use to create border radius if you want one, vary the thickness of the border, and select a color for the border. screenshot of attributes inspectorYou can vary the values to make the radius greater and the width thicker also, plus you can change the color. Pay very close attention to the spelling otherwise this won't work.

All rows in UILabel not visible depending on text

I have a label that goes across the screen with a margin of 20 on each side and the line attribute is set to 0
This is what it looks like in Interface Builder
There is no problem if the text fits on a single row but if it needs another row, then the second row isn't always visible.
If I use the text and the image above, then the result looks like this in the simulator
But if I add some more text then the second row is visible.
Interface Builder:
iOS Simulator:
Am I missing something with the constraints?
You can download the project here and try for yourself. I've added a textview and a button to easier debug it.
You can calculate the desired height in code. It's just a few lines.
https://gist.github.com/danielphillips/1005520
credit DanielPhillips

RichText label or 'flow' layout for text in iOS (Xamarin/MonoTouch)

I am trying to repduce a similar sort of layout as in the screenshot below from the Digg app..
Notice that each list entry has a title in bold followed by the source, posted time and finally if there is enough space the start of the description line.
The question is what is the best way to achieve this in iOS? With some posts having longer titles than others I cannot simply say that the title label is 40px high and then place the Source label at 45 as the title will sometimes be longer and sometimes shorter.
Do I have to calculate the height of the label based on its contents before arranging the layout or is there some better way of doing this in iOS so that the views 'below' are automatically moved down?
Another alternative would be some sort of rich text label that I could add all the text to and have it automatically wrap round moving the later text down but I cannot find any sort of control in standard iOS / Xamarin (MonoTouch).
Any pointers would be greatly appreciated?
If you are using a storyboard the simplest way to achieve this result is to define different prototype cells. For example, you could define four different prototype cells, each one with a different layout like those shown in the example picture you provided. You can dequeue the appropriate cell based on the content you want to display so there is no need to adjust the layout in the code.
If you are doing everything in code, it's a lot more complicated since you have to build your own "layout engine" to adjust size and position of the views in your cell. You can have a look at XibFree or use MonoTouch.Dialog as suggested in the comments.

add button in textview -xcode

How can I add a button in textview? for example..
textView.text=#"text here\n\n text also here\n\n text here aswell";
How can I add a button after each "\n\n" or along the text?
You can create a object of UIButton and add it as subview to yout textview.
You need to preset the frame of the button So the text must be statis and you must know the position of the button in advance.
so your \n\n creates a paragraphs
You can do it without static text just split your text in separate textviews by \n\n, add them to your scrollview. You have to measure your text paragraphs height to set the right frame for textviews and leave gaps for buttons. I would rather use tableview so you dont have to worry about that. Add buttons in between, it is doable.
you may reconsider adding buttons along the text this way (you can but it is really convoluted way of doing things), use webview for that as already stated here by others

Resources