Is it possible to adjust textview with small picture inside it? - ios

I moved from android to Swift. In android we could assign a drawable to the left or right of the text, we could do this in XML.
for example this XML for a textView with picture on the left:
<TextView
android:id="#+id/myTextView"
android:layout_width="match_parent"
android:text="This is test text view and it is showing"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/myImage" />
so the image "myImage.png" will be same as the picture below.
I wonder if there is something similar in swift for ios ?

In Xcode Interface Builder, you can't really do that with one item. The best solution is to create a textView and an imageView, then pin the two together with aligning and margins in auto layout.

Related

Xamarin Android - How to get rid of inexplicable Margin/Padding around a WebView?

I have a LinearLayout which contains a WebView inside of it. This WebView loads a static HTML file. I want the WebView's size (width and height) to match that of the LinearLayout, but for some inexplicable reason there is this mysterious margin or padding preventing the WebView from filling the LinearLayout. To illustrate, I have given the LinearLayout a black border and the content of the HTML file being loaded by the WebView a red border:
Here is the axml for these elements:
<LinearLayout
android:id="#+id/alertViewProductReplacement_ReplacementProductLinearLayout"
android:layout_width="100dp"
android:layout_height="225dp"
android:layout_margin="0dp"
android:padding="0dp"
android:fillViewport="true"
android:layout_toRightOf="#id/alertViewProductReplacement_arrow"
android:background="#drawable/dpBorder"
android:orientation="vertical">
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/replacementProductsWebView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:layout_margin="0dp"
android:padding="0dp"
android:background="#null"/>
</LinearLayout>
Some likely redundant things to point out above that I have tried is setting the margin and padding for both to 0, setting the height and width of the WebView to "fill_parent", and setting fillViewport="true". I have also tried forcing 0 margin and padding programatically as well as changing the LinearLayout to a RelativeLayout. None of these things have had any effect, it always looks the same with that small amount of space between them.
I'll also point out that the HTML content itself has no margin or padding outside of the red border, this is clearly observed if I load the HTML file up in a browser directly:
I have even tried to just brute force hack it by setting a negative margin both at the axml level as well as at the HTML file level, but I can't get that mysterious margin to budge no matter what I try so I have finally turned here.
WebView is kind of web browser and has some default margin in body (like other web browsers). you can remove that margin using CSS like so:
<body style="margin:0;">
More info: Remove unwanted White Space in WebView Android

Gravity in iOS like in android

Is there any easy way to center controls in a view in iOS like using android:gravity="center_horizontal" in android? I could calculate the position for each control before adding it and recalculate when the screen is rotated, but I'm wondering if there is a better solution for this.
Please pay attention, layout_gravity is different from gravity in Android.
layout_gravity is for the alignment in container view and gravity for the content alignment in self.
After reading your question, I think you mean layout_gravity not gravity.
Okay, Let's discuss about UIStackView.
What is UIStackView ,as the documentation said , it is just a container view which can control the distribution, aligment, spacing ,xxx on its subviews, and is created with autoLayout, it means you don't need to manage those constraints on the subviews.
As you see, the alignment of stackView will apply to all the controls on it not single one.
To achieve the effect like layout_gravity , you have to manage the constraints manually .
and the constraints on the center button .

Static width in text field

please how can i have a static width for my Text Fields.
I have a Login View Controller (portrait) in which i have an image (logo of the App), username text field, password text field and a button to log in.
When i run it in an Iphone it looks pretty good, but in Ipad all looks stretched.
What can i do so this elements looks the same in both devices? (i want them to look as the Iphone shows).
I don't want them to resize.
Thanks a lot!
If you want an element to be an exact size you would update the width and height constraints to be your desired number.
Set your textFields width and height properties to your desired size in Attributes inspector panel or do it programmatically.
I would recommend you to use Auto Layout as that will help you make your design beautiful in all resolutions and sizes.
Thanks all for your answer, i erase the "Leading space to container" and "Trailing space to container" in each one of the elements.
It is no resizing anymore :)

Change Text Alignment in UITableViewCell On Rotate

I am using sizing classes to turn two xib files (iPhone vs iPad) into one. Most orientations have a 2x2 grid of UILabels above a UITextView. However, for iPhone portrait, I want the UILabels to stack vertically. I have this working great with sizing classes. I was disappointed to see, however, that sizing classes don't allow for the change of text alignment. Refer to my diagrams below. In the main orientation I have the text in the yellow and blue UILabels right-aligned. In the iPhone portrait orientation I want the same UILabels to have left-aligned text. How can I change this if the user rotates the device while viewing these table cells? I figure there's a better way of doing this than reloading the table.
I dont think it is possible to setup the text alignment based on the screen orientation or device. however you can create 2 labels, one with left aligned text and the other with whatever you're using otherwise, in a way that they are exclusive to the screen layout you're using. I.e. one label for iPhone and one label for everything else.
You can select then, for that UILabel object in storyboard, which screen layouts it will be installed for.

UILabel doesn't show text properly

I have UILabel in interface builder like this (creating text and use Cmd + =)
but when i run the program on emulator or real device, it looks like this
the answer from here can solve my issue but it isn't the best way because i don't want to create all my label as an IBOutlet for calling sizeToFit and i also don't want to scale down my text.
is there any way to display text in the device as it shows in interface builder without additional code or configuration?
Thanks
If you're just strictly not wanting to do any of it in code, simply press Editor -> Size to Fit Content when you have the label selected in IB.
Select your label in the interface builder, and then in the utility area found on the right hand side, go to the "Size Inspector", look for this icon -->
In there you will see options to set your label's origin, width and height
Increase the "width" of your label and that should fix your problem

Resources