slanted-text-compose
Github repository address
introduce
Recently want to achieve a tilting text label effect in the corner, looking for only View system, so I wrote a simple implementation
Import and use
- Gradle import
// Add the jitpack repository
maven { url 'https://jitpack.io' }
Copy the code
- use
SlantedText(
text = "Slant",
textSize = 15.sp,
bold = false,
thickness = (width * 100f).dp,
padding = 16.dp,
slantedMode = SlantedMode.TOP_RIGHT
) {
// For the content under the tag, just write a random Box with a color
Box(
modifier = Modifier
.size(150.dp, 100.dp)
.background(Color.Blue)
)
}
Copy the code
Parameter interpretation
- Text: indicates the label text
- TextSize: textSize
- Bold: Indicates whether the text is bold
- Thickness: label thickness
- Padding: Distance from the label to the corner
- SlantedMode: Placement mode (being able to specify which corner to put in)
Realize the principle of
Use Canvas to draw labels directly
See: SlantedText kt# L56
License
MIT