How can i create a component like this is NS?
How to give hexagon shape to ImageView
I want to create a image component that has a hexagon look, but i cant figure it out how to extend nativescript classes correctly in order to obtain this result.
How can i create a component like this is NS?
How to give hexagon shape to ImageView
I want to create a image component that has a hexagon look, but i cant figure it out how to extend nativescript classes correctly in order to obtain this result.
This is a perfect case for clip-path
, which is a CSS property that NativeScript supports out of the box!
View:
<ContentView width="150" height="150" class="someimage hexagon"></ContentView>
CSS:
.someimage {
background-image: url("~/assets/images/myimage.jpg");
background-repeat: no-repeat;
background-position: center;
background-size: cover;
}
.hexagon {
clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
}
Or you can apply it directly to an image, like in this example:
<Image src="~/assets/images/myimage.jpg" class="hexagon"></Image>
You can tweak the appearance of the hexagon with this amazing tool: http://bennettfeely.com/clippy/