I just started learning react native and am trying to write some practice programs, but for some reason I haven't been able to round the corners of a text element. I've been using borderRadius but that isn't working. Here is the entire code:
import React from 'react';
import { StyleSheet, Text, View, Button, Alert } from 'react-native';
export default function App() {
function myButtonPressed(){
Alert.alert("Logout")
}
return (
<View style={styles.container}>
<Text style={styles.text}> Login </Text>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
text: {
fontSize: 30,
backgroundColor: "#BB2cd9",
paddingVertical: 12,
paddingHorizontal: 40,
color: '#ffffff',
borderRadius: 10
}
});
Am I missing something that I need to import?
You can use borderRadius: number with overflow: 'hidden', in any react UIComponent. i.e. <Text>,<View>,<Button> etc.
style like:
render() {
return <View style = {{ height:100, width:100, backgroundColor: 'green', borderRadius: 10, overflow: 'hidden'}} ></View>
}
Node: Takecare about overflow: 'hidden'
Please apply borderRadiu sto the view component, Do checkout the code and working solution :
working solution
import * as React from 'react';
import { Text, View, StyleSheet } from 'react-native';
import Constants from 'expo-constants';
// You can import from local files
import AssetExample from './components/AssetExample';
// or any pure javascript modules available in npm
import { Card } from 'react-native-paper';
export default class App extends React.Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.paragraph}>
Change code
</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
marginTop:100,
marginLeft:50,
justifyContent: 'center',
paddingTop: Constants.statusBarHeight,
backgroundColor: '#ecf0f1',
padding: 8,
height:50,
width:200,
borderRadius:20
},
paragraph: {
margin: 24,
fontSize: 18,
fontWeight: 'bold',
textAlign: 'center',
borderRadius:20
},
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With