How to add image inside an Textview in Nativescript? - nativescript

I have been trying to build a textview which can hold image as well. As it works in iOS using NStextAttachment and NSattributedString. Maybe somehow I have inject the image to the FormattedString . Does anyone have any idea? PLease help

I think there is not possible for now. You can try some ways like StackLayout with horizontal orientation. So you need to work on css for same background colors and size etc...
<StackLayout orientation=“horizontal”>
<TextField .... />
<Image .... />
</StackLayout>

Related

Xamarin forms Grid with radius and background color

I am developing an app for UWP using xamarin forms.
I need create a screen like this
For UWP but I don't know how do it the Grid with Radius and backgrondcolor .
I try it with a frame but when I add the BackgroundColor property the Radius disappears.
I try with https://github.com/paulpatarinski/Xamarin.Forms.Plugins/tree/master/RoundedBoxView but don't work for UWP.
Thank you so much
UPDATE: SOLUTION
I find the solution. Make a custom render of Frame for UWP.
Here's the code : https://github.com/migueBarrera/XamarinRoundedFrame with the final image
You should try Frame instead of boxview and if you want to use grid than you have to make custom renderer for the grid.
Frame seems to work well, at least on Android.
This is my XAML
<Frame BackgroundColor="LawnGreen"
CornerRadius="25"
VerticalOptions="StartAndExpand"
Margin="20">
<StackLayout>
<Label Text="Entry"/>
<Label Text="Entry"/>
<Label Text="Entry"/>
<Button Text="Entrar" Margin="10, 30, 10, 20"></Button>
</StackLayout>
</Frame>
And this is the page

Image within an ellipse XAML

I am using VS2013, Windows 8.1 and developing a windows store app.
Im creating a simple contacts - listview, that displays the contact details along with contact image within an ellipse. When I click on the listview item, I want to display the contact details on right side of the page. Now the issue I am facing is, I am not able to fit the contact image to the right size on the ellipse on the right side pane.
I am able to achieve it in my list view since its an smaller ellipse.
Important: I do not want the image to look stretched/Zoomed in /Zoomed out. It should exactly look like how it appears within the list view. (For list view , I have used Ellipse.Fill along with Imagebrush, but relatively smaller sized ellipse)
What I tried so far:
Ellipse.Fill property which paints the image to size, but the image looks stretched.
I tried setting "Stretch" property within the image tag within ellipse, but did not work.
I tried Image.clip, but I do not have "EllipseGeometry" option, instead only RectangleGeometry.
Lastly I created an image that has a transparent center and I place this frame over the contact image like a mask. This works well on some resolutions. But when some other resolution, the contact images which are binded from backend, go beyond the frame, although I set "MaxHeight" or "Height" properties.
I want to do it the right way, since I feel adding an image mask might not be a great way to achieve this. Please help!
I tried this for listview, n works fine, But the same code for right pane looks stretched (I have tried removing stretch attirbute, or tried other options like Stretch ="None" /"Uniform" etc )
I have attached screenshot.
Since code isn't clearly mentioned, you can do it with both Ellipse and Border. Here's the code snippet
<!--With Ellipse-->
<Ellipse Height="200"
Width="200">
<Ellipse.Fill>
<ImageBrush Stretch="Uniform"
ImageSource="Assets/profile.png" />
</Ellipse.Fill>
</Ellipse>
<!--With Border-->
<Border Height="200"
Width="200"
CornerRadius="150">
<Border.Background>
<ImageBrush Stretch="Uniform"
ImageSource="Assets/profile.png" />
</Border.Background>
</Border>
Here's the result
The properties "AlignmentX AlignmentY" within ImageBrush solved my issue.
If your image has portrait orientation, then you can use Stretch, AlignmentX, AlignmentY properties of ImageBrush like this to achieve best preview result
<Border CornerRadius="20" BorderThickness="1" BorderBrush="DarkGoldenrod">
<Ellipse Width="40" Height="40">
<Ellipse.Fill>
<ImageBrush ImageSource="{Binding PractitionerPhoto}" Stretch="UniformToFill" AlignmentX="Center" AlignmentY="Top" />
</Ellipse.Fill>
</Ellipse>
</Border>

Xamarin Forms Controls with borders

In my Xamarin forms application I want to add borders to a Grid / StackPanel. Also the background color will be transparent. I used frame control , but when I set background color to transparent the border also not shown. Please help me?
You basically have two possibilies, since this is not yet supported in Forms, where the first is to use BoxViews as explained on SO in this post.
Otherwise, you can wrap a StackLayout around your View (the StackLayout or Grid as you mentioned) with a BackgroundColor and Padding of 0.5 as explained here.
Let me know if you need more concrete examples.
There's no Border property for GridView, but:
Just set grid.BackgroundColor to your desired border color value, then set grid.ColumnSpacing and grid.RowSpacing to some value and make sure all controls you add to the grid have own BackgroundColor set correctly.
A BoxView can be used for border purpose. In the following XAML code, note that FillAndExpand option is used for HorizontalOptions of the StackLayout
<StackLayout VerticalOptions="Start" HorizontalOptions="FillAndExpand" >
<BoxView BackgroundColor="Cyan" HeightRequest="5" VerticalOptions="End" HorizontalOptions="FillAndExpand" />
<BoxView BackgroundColor="Cyan" HeightRequest="1" VerticalOptions="Start" HorizontalOptions="FillAndExpand" />
</StackLayout>
There's no Border property for GridView, but:
Just set grid.BackgroundColor to your desired border color value, then set
grid.ColumnSpacing and grid.RowSpacing to some value and make sure all controls you add
to the grid have own BackgroundColor set correctly.
You also have to set Grid.Padding to whatever the border width you want.

how to show a zoomable image in a windows 8 (WinRT) app?

Is it possible to put a image into a control in WinRT and then let the user zoom in and out etc?
Yes!
The easiest possible way is to put it inside a scrollviewer. You can zoom in and out whatever you like that way!
<ScrollViewer MaxZoomFactor="3"
MinZoomFactor="0.5"
ZoomMode="Enabled">
<Image Source="/Assets/logo.png" Width="200" Height="200"/>
</ScrollViewer>

Background Image on an AdControl

Is it possible to add a background image to an AdControl? Or is it possible to place an AdControl over an image and give it a transparent background?
I have been trying several things to try to accomplish this - no luck so far.
You can try putting a AdControl inside a Border Control. You can set the Image to a Border Control.
<Border Background="Red">
<AdControl id="adControl1" height=80 width="480" />
</Border>
Most of the Ads have a Transparent Background.
Hope this helps.

Resources