1、把手機屏幕分成上下。上下兩部分都採用Linearlayout方式布局 <LinearLayout> <LinearLayout> 上半部分 </LinearyLayout> <LinearLayout> 下半部分 </LinearyLayout> </LinearLayout>2、下半部分LinearLayout高度固定,上半部分LinearyLayout設置layout_weight權重,占滿剩餘屏幕空間 <LinearLayout> <LinearLayout android:layout_height="wrap_content" android:llayout_weight="1"> //設置高度自適應,並且權重為1 </LinearyLayout> <LinearLayout android:layout_height="50px"> //下半部分設置高度固定 </LinearyLayout> </LinearLayout>3、下半部分LinearLayout中添加按鈕,設置android:gravity右對齊。 <LinearLayout android:layout_height="50px" android:gravity="right"> //下半部分設置高度固定 <button andtoid:text="右下角按鈕"/> </LinearyLayout>
Ⅱ IOS UIButton 文字不全,被壓縮了。比如"P..y"
如果你沒有使用AutoLayout
你需要改變button.frame = CGRectMake(xx, xx, 能夠顯示全文字的合適寬度, 比字體大2.0f的高度)
如果你使用了AutoLayout
你需要改變button的width Constraint至能夠顯示全文字的合適寬度.
Ⅲ Uibutton 標題文字位置怎麼靠下方
雙擊button,會出現button_click事件的方法,在裡面寫form2 f=new form2();f.show();就OK了 如果對您有幫助,請記得為滿意答案,!祝您生活愉快!vaela
Ⅳ ios中怎麼設置uibutton上字體的大小
1.在IOS程序中設置UIButton的字體大小:
btn.frame = CGRectMake(x, y, width, height);
[btn setTitle: @"search" forState: UIControlStateNormal];
//設置按鈕上的自體的大小
//[btn setFont: [UIFont systemFontSize: 14.0]]; //這種可以用來設置字體的大小,但是可能會在將來的SDK版本中去除改方法
//應該使用
btn.titleLabel.font = [UIFont systemFontOfSize: 14.0];
[btn seBackgroundColor: [UIColor blueColor]];
//最後將按鈕加入到指定視圖superView
[superView addSubview: btn];
附:創建按鈕的兩種方法:
1、動態創建
btnfont = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btnfont setFrame:CGRectMake(100, 10, 120, 40)];
[btnfont addTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
[btnfont setTitle:@"字體" forState:UIControlStateNormal];
btnfont.backgroundColor=[UIColor clearColor];
[self.view addSubview:btnfont];
2、在xib文件中已經創建好,通過tag獲取按鈕
UIButton *testButton= (UIButton*)[self.view viewWithTag:100];
[testButton addTarget:self action:@selector(test:) forControlEvents:UIControlEventTouchUpInside];
注冊事件
-(void) test: (id) sender{
UIAlertView *av = [[[UIAlertView alloc] initWithTitle:@"ceshi" message:@"test11111" delegate:nil cancelButtonTitle:@"OK"otherButtonTitles:nil] autorelease];
[av show];
}
2.設置UIButton的文字顯示位置、字體的大小、字體的顏色
btn.frame = CGRectMake(x, y, width, height);
[btn setTitle: @"search" forState: UIControlStateNormal];
//設置按鈕上的自體的大小
//[btn setFont: [UIFont systemFontSize: 14.0]]; //這種可以用來設置字體的大小,但是可能會在將來的SDK版本中去除改方法
//應該使用
btn.titleLabel.font = [UIFont systemFontOfSize: 14.0];
[btn seBackgroundColor: [UIColor blueColor]];
//最後將按鈕加入到指定視圖superView
[superView addSubview: btn];
tvnamelabel=[[UIButton alloc]initWithFrame:CGRectMake(5,5,200,40)];
這樣初始化的button,文字默認顏色是白色的,所有如果背景也是白色的話,是看不到文字的,
btn.contentHorizontalAlignment= ;//設置文字位置,現設為居左,默認的是居中
[btn setTitle:@「title」forState:UIControlStateNormal];// 添加文字
有些時候我們想讓UIButton的title居左對齊,我們設置
btn.textLabel.textAlignment = UITextAlignmentLeft
是沒有作用的,我們需要設置
btn.contentHorizontalAlignment = ;
但是問題又出來,此時文字會緊貼到做邊框,我們可以設置
btn.contentEdgeInsets = UIEdgeInsetsMake(0,10, 0, 0);
使文字距離做邊框保持10個像素的距離。
設置UIButton上字體的顏色設置UIButton上字體的顏色,不是用:
[btn.titleLabel setTextColor:[UIColorblackColor]];
btn.titleLabel.textColor=[UIColor redColor];
而是用:
[btn setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];
Ⅳ 如何調整UIButton裡面的文字位置
關鍵在:
[m_iknowBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 10, 18, 0)];
其中
UIKIT_STATIC_INLINE UIEdgeInsets UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom,CGFloat right) {
UIEdgeInsets insets = {top, left, bottom,
right};
return insets;
}
表示
這個表示title往右邊偏移10像素,往上面偏移18像素。
第一個參數top如果為正表示往下偏移,第二個參數left如果為正表示往右偏遠,第三個參數bottom如果為正表示往上偏移,第四個參數right如果為正表示往左偏移。
//右對齊
[login_bt setContentHorizontalAlignment:];
Ⅵ UIButton怎麼添加下劃線
1。如果你的Button不顯示文字的話,直接設置其title就行了,然後設置其titleEdgeInsets.2.
如果顯示文字的話,就直接添加一個UILabel就行了。label.text
=
@"_____________"
Ⅶ 如何設置UIButton中image與title在UIButton中居中顯示
自定義一個TabBar,有四個Tab。每個tab均有一個圖片與文字兩部分組成,圖片在上,文字在下,都相對tab左右居中,當然還需要點擊。如果自己寫一個View,裡面放一個UIImageView、UILabel、UIButton(UIGestureRecognizer)。這都是很容易實現的。
但是突然一想,這幾個元素,UIButton本來就就有,UIButton是能直接設置image與title的,那麼把這兩部分,移動一下位置應該就ok了。事實也是如此,但是過程卻讓我有點蛋疼。
設置UIButton的image與title均為設置他們的UIEdgeInsets。這點也沒什麼問題。但是它的UIEdgeInsets與我想的卻不太一樣,這個不一樣如果寫出來,就太麻煩了。就不寫了。下面我就把正確的代碼貼一下:
CGRect titleBounds = tab.titleLabel.bounds;
CGRect imgBounds = tab.imageView.bounds;
UIEdgeInsets imgInsets = UIEdgeInsetsZero;
UIEdgeInsets titleInsets = UIEdgeInsetsZero;
imgInsets.bottom = tab.frame.size.height / 2 - 4;
imgInsets.right = - titleBounds.size.width;
titleInsets.top = tab.frame.size.height / 2 - 4;
titleInsets.left = - imgBounds.size.width;
[tab setImageEdgeInsets:imgInsets];
[tab setTitleEdgeInsets:titleInsets];
註:tab就是一個UIbutton。
按以上的代碼,是能實現這個效果的。
在嘗試的過程中,我發現,UIButton的titlelabel與imageview都是有frame的,我視圖設置他們的frame來實現居中的效果,結果發現,只要點擊後,就會恢復原形(上下結構就變成左右結構了)。非常神奇的效果。不知道怎麼回事兒。
Ⅷ 怎麼修改 UIButton 的文字
// button.titleLabel.textAlignment = NSTextAlignmentLeft; 這句無效
button.contentHorizontalAlignment = ;
button.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
這里使用
button.titleLabel.textAlignment = NSTextAlignmentLeft; 這行代碼是沒有效果的,這只是讓標簽中的文本左對齊,但
並沒有改變標簽在按鈕中的對齊方式。
所以,我們首先要使用
button.contentHorizontalAlignment = ; 這行代碼,把按鈕的內容(控制項)
的對齊方式修改為水平左對齊,但是這們會緊緊靠著左邊,不好看,
所以我們還可以修改屬性:
button.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
這行代碼可以讓按鈕的內容(控制項)距離左邊10個像素,這樣就好看多了
Ⅸ ios 怎麼動態改變 UIButton的title文字
ios中tabbar得title和navigationbar的title修改方法如下: self.tabBarItem.title = [NSString stringWithFormat:@""];//來設置tab的title self.title = @"";//設置navigationbar的title;