uibutton

How can I create a UIButton supporting dynamic multiline text with image background?

最后都变了- 提交于 2020-01-03 04:25:14
问题 I'm trying to create a UI element on iOS that expands or contracts to fit dynamic, often multiline text. I need to put an image underneath the text that looks a lot like a message bubble. However, I only need one of these in my entire UI, so a table view seems overkill - unless reasonably necessary. I've tried to use a UILabel for this purpose, but it seems to have very limited support for background images. I can only get it to tile the image, which is not what I want. It seems that a

Swift: How to change views' background from other views

本小妞迷上赌 提交于 2020-01-03 03:06:49
问题 My task is to create an app where I can change and save the background. I wanted to do something more elaborate, so I decided to create a color menu that allows me to change all of the views' backgrounds. Now, I have the menu, and I know how to set and save pictures/ colours in the background. But I don't know how to do it from a view controller to another. Right now my code changes its own view's background. This is my code (I know it's a lot...): First of all I have 2 extensions that allows

Identify a UIButton that is pressed in swift?

半世苍凉 提交于 2020-01-03 03:05:34
问题 How can I identify a UIButton element as a string and use that string in a function call? I want to be able to know what button has been pressed and then provide information based on that button that has been pressed. Would I use String Interpolation? I then want to use the string and run a query from the Foursquare API. Below is the code I have been working on: Firstly the button names: let buttonNames = ["african", "buffet", "burger", "chinese", "fries", "grill", "icecream", "jap", "mex",

uinavigationController's toolbar with custom items

我怕爱的太早我们不能终老 提交于 2020-01-03 02:30:12
问题 I am trying to use the NavigationController's toolbar in my app. This toolbar's toolbarItems are suppose to change depending on which view controller is presented. this is very basic. What I am trying to do is to add custom buttons to the toolbar using the UIBarButtonItem's "initWithCustomView:" method. However, the button won't show up on the toolbar. But if I create the UIBarButtonItem using the "initWithTitle:" or "initWithBarButtonSystemItem:" method, the button show up. For example, look

UIButton相关的知识点

梦想的初衷 提交于 2020-01-03 02:16:25
链接地址:http://blog.sina.com.cn/s/blog_793f11ce0100teyj.html 在viewDidLoad 事件中绘制 // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; //绘制按钮 UIButton *btn=[UIButton buttonWithType:UIButtonTypeRoundedRect]; //绘制形状 //确定宽、高、X、Y坐标 CGRect frame; frame.size.width=100; frame.size.height=30; frame.origin.x=320/2-50; frame.origin.y=480/2-30; [btn setFrame:frame]; //设置Tag(整形) btn.tag=0; //设置标题 [btn setTitle:@"按钮" forState:UIControlStateNormal]; //设置未按下和按下的图片切换 [btn setBackgroundImage:[UIImage imageNamed:@"bus.png"] forState

iPhone: Is it possible to have an 'info'-button in all views in my app?

北战南征 提交于 2020-01-02 21:00:16
问题 As mentioned in the title, how do I implement such a functionality? I am using the code below, (in my viewDidLoad), to get the button on my Navigation Controller of my main view. UIButton* infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight]; [infoButton addTarget:self action:@selector(viewWillAppear:) forControlEvents:UIControlEventTouchUpInside]; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:infoButton]; Not sure how I can get it displayed in

【IOS开发笔记03-视图相关】简单计算器的实现

做~自己de王妃 提交于 2020-01-02 20:18:22
UIView 经过前几天的快速学习,我们初步了解的IOS开发的一些知识,中间因为拉的太急,忽略了很多基础知识点,这些知识点单独拿出来学习太过枯燥,我们在今后的项目中再逐步补齐,今天我们来学习APP视图相关知识。 视图即UIView对象,我们上次用的按钮UIButton、UILabel或者UITableView皆是其子类;视图知道如何绘制自己与前端一致有一个层次的概念。 任何一个应用都会有一个UIWindow对象,与浏览器对象一致,他作为容器角色而存在,负责装载所有的视图控件,每个加入的视图便是一个子视图:subview,视图嵌套便形成了我们看到的APP界面,这点类似与html的dom结构。 视图的绘制分为两步: ① 层次结构上的每个视图(包括根视图UIWindow)分别绘制自身,视图将自己绘制到图层(layer)上,每个UIView都拥有一个layer属性,指向一个CALayer对象 ② 所有视图的图像最终组成为一幅图像,绘制到屏幕上 为了更好的了解UIView的相关知识,我们这里做一个简单的计算器来说明其知识点吧。 其实说明这个知识点我可以选择很多项目之所以会选择计算器是因为内部会碰到数字与字符串转换,四则运算问题,也会遇到控件绑定事件等行为,帮助我们巩固基础吧。 这里新建一个单页应用:Calculator-app,自从昨天我知道了拖控件居然需要以拖动的方式建立关联后

Why doesn't UIButton showsTouchWhenHighlighted work when the button is on a UITableViewCell?

ε祈祈猫儿з 提交于 2020-01-02 14:02:26
问题 I put a UIButton on a UITableViewCell and set its showsTouchWhenHighlighted property to YES . The cell's selection style is UITableViewCellSelectionStyleNone . I have a selector that gets called when the button is tapped and it's working fine, so the button is getting the touch events fine. However, button doesn't show the highlight effect when touched. When I put this button on a UIView , the highlight effect works. How can I make this work when the button is placed on the cell? 回答1: Are you

UIButton titleEdgeInsets [duplicate]

蹲街弑〆低调 提交于 2020-01-02 04:45:31
问题 This question already has answers here : Aligning text and image on UIButton with imageEdgeInsets and titleEdgeInsets (13 answers) Closed 6 years ago . titleEdgeInsets used to align the title and the picture on the button. I did image on the left and title on the right.But when I click on the button, the title is shifting to the left. Thank you UIImage *image = [UIImage imageNamed:imageName]; [self setImage:image forState:UIControlStateNormal]; CGSize imageSize = self.imageView.frame.size;

iOS SDK: Dismiss keyboard when a button gets clicked?

做~自己de王妃 提交于 2020-01-02 04:32:55
问题 How can I dismiss the keyboard when the user clicks a button? A short example for a better understanding: the user edits some text in some textfields and at the end he doesn't click "Done" or smething else on the keyboard, but he clicks on an button "Save" while the keyboard is still shown. So, how can I now dismiss the keyboard? Thx. Regards, Daniel 回答1: in button action write, if([textField isFirstResponder]){ [textField resignFirstResponder]; } if there are more textfields get the current