显示uitextfield但未显示按钮

时间:2016-06-07 07:24:25

标签: ios uibutton

显示

UITextField但不显示UIButton。 如何显示按钮??

UITextField *password = [[UITextField alloc] initWithFrame:CGRectMake(30.0, 150, 300, 30.0)];
password.delegate = self;
[password setBorderStyle:UITextBorderStyleRoundedRect];
[password setClearButtonMode:UITextFieldViewModeAlways];
password.placeholder = @"Password";
[password setFont:[UIFont systemFontOfSize:10]];
[self.view addSubview:password];
//button
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(30, 200 , 50, 50)] ;
[button addTarget:self action:@selector(clicked) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button = [UIButton buttonWithType: UIButtonTypeSystem];

 [self.view addSubview:button];

2 个答案:

答案 0 :(得分:1)

尝试添加按钮的<Page.Resources> <CollectionViewSource x:Name="cvs" IsSourceGrouped="True" Source="{x:Bind MyVM.Grouped, Mode=OneWay}"/> </Page.Resources> <StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <ListView ItemsSource="{Binding Source={StaticResource cvs}}"> <ListView.GroupStyle> <GroupStyle> <GroupStyle.HeaderTemplate> <DataTemplate> <TextBlock FontSize="15" FontWeight="Bold" Text="{Binding Key}"/> </DataTemplate> </GroupStyle.HeaderTemplate> </GroupStyle> </ListView.GroupStyle> </ListView> </StackPanel> BackgroundColor

TitleColor

答案 1 :(得分:0)

你正在两次初始化按钮。

UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(30, 200 , 50, 50)] ;

button = [UIButton buttonWithType: UIButtonTypeSystem];

初始化系统按钮并稍后设置其帧。

UIButton *button = [UIButton buttonWithType: UIButtonTypeSystem];
button.frame = CGRectMake(30, 200 , 50, 50);

希望这会有所帮助。