我有一个UITextView,我从csv逐行写入值。
典型的行
" |"代表屏幕的边缘
| name of place timeAtPlace |
| name of place timeAtPlace |
| longer name of place timeAtPlace |
文本左对齐,但我也希望timeAtPlace与右对齐。 实现这个目标
| name of place timeAtPlace |
| name of place timeAtPlace |
| longer name of place timeAtPlace |
我的想法是将字符串填充到行的长度。为此,我需要知道当前设备的线路上可以容纳多少个字符。
有没有办法计算这个,字体点大小和设备点大小之间有什么关系吗?或者有没有办法划分屏幕(*我说屏幕,但在这种情况下意味着UITextView)大小的字体大小,以知道线上可以容纳多少个字符?
答案 0 :(得分:0)
如果您想要使用评论中提到的public class ToastMessage {
private Context context;
private static ToastMessage instance;
/**
* @para
m context
*/
private ToastMessage(Context context) {
this.context = context;
}
/**
* @param context
* @return
*/
public synchronized static ToastMessage getInstance(Context context) {
if (instance == null) {
instance = new ToastMessage(context);
}
return instance;
}
/**
* @param message
*/
public void showLongMessage(String message) {
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
}
/**
* @param message
*/
public void showSmallMessage(String message) {
Toast.makeText(context, message, Toast.LENGTH_LONG).show();
}
/**
* The Toast displayed via this method will display it for short period of time
*
* @param message
*/
public void showLongCustomToast(String message) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
View layout = inflater.inflate(R.layout.layout_custom_toast, (ViewGroup) ((Activity) context).findViewById(R.id.ll_toast));
TextView msgTv = (TextView) layout.findViewById(R.id.tv_msg);
msgTv.setText(message);
Toast toast = new Toast(context);
toast.setGravity(Gravity.FILL_HORIZONTAL | Gravity.BOTTOM, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
}
/**
* The toast displayed by this class will display it for long period of time
*
* @param message
*/
public void showSmallCustomToast(String message) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
View layout = inflater.inflate(R.layout.layout_custom_toast, (ViewGroup) ((Activity) context).findViewById(R.id.ll_toast));
TextView msgTv = (TextView) layout.findViewById(R.id.tv_msg);
msgTv.setText(message);
Toast toast = new Toast(context);
toast.setGravity(Gravity.FILL_HORIZONTAL | Gravity.BOTTOM, 0, 0);
toast.setDuration(Toast.LENGTH_SHORT);
toast.setView(layout);
toast.show();
}
}
,并且想要在右侧对齐时不显示文字而显示文字,那么您可以执行类似的操作,
UILabel