如何以编程方式移动UIButton?

时间:2015-08-21 09:53:05

标签: ios swift cocoa-touch layout

我想移动一个UIButton: from here

以编程方式在屏幕底部,我该怎么做?

1 个答案:

答案 0 :(得分:2)

您的问题不是很清楚,但您可以按如下方式获取有关屏幕尺寸的信息:

Template.header.onRendered(function() {
  $("#sneak-preview-btn").popover({
    container: 'body',
    template: '<div class="popover work-journals-popover" role="tooltip"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>',
    animation: true,
    placement : 'right',
    html : true,
    delay: { "show": 500, "hide": 100 },
    trigger : 'manual',
    content : function() {
      var popTitle = "<h5>Peek last 5 activities completed by your team mates.</h5>";
      var formAddEntry = "<form id='add-entry'><div class='form-group'><input id='entry' name='entry' type='text' class='form-control' placeholder='Add a new task you completed'/></div></form>";
      var entriesLimit = 5;
      var htmlEntryList = "";
      var myEntries =  WorkJournals.find({userId : Meteor.userId()}, {sort : {createdAt : -1}, limit : entriesLimit}).fetch();

      if (myEntries) {
        htmlEntryList ="<div class='scroll-journal-entries'><ul>";
        myEntries.map(function(en) {
          htmlEntryList += libGetHtmlJournalEntry(en);
        });
        htmlEntryList += "</ul>";
        var companyUsers = Profiles.find({companyId : libGetCompanyIdFromUser(Meteor.userId())}, {fields : {userId : 1}}).fetch();
        companyUsers.filter(function(user) {
          if (user.userId !== Meteor.userId())
            htmlEntryList += libGetHtmlJournalEntries(user.userId, entriesLimit);
        });

        htmlEntryList += "</div>";
      }
      return "<div>" + popTitle + formAddEntry + "<p>" + htmlEntryList + "</p><button id='close-sneak-preview' type='button' class='btn btn-default btn-xs pull-right'>Close</button><br>" + "</div>";
    }
  });
  //manage lost focus
  $(document).on('blur', '.popover', function(e) {
    e.preventDefault();
    $("#sneak-preview-btn").popover('hide');
  });

  //manage submit
  $(document).on('submit', '#add-entry', function(e) {
    e.preventDefault();
    WorkJournals.insert({
      companyId: Profiles.findOne({userId : Meteor.userId()}).companyId,
      userId : Meteor.userId(),
      entryText : $('#entry').val(),
      createdAt : new Date().getTime()
    });
    $("#sneak-preview-btn").popover('hide');
    libShowAlert('messages-heading-row', 'A completed task was added to your activity log', 'alert-nice');
  });

  $(document).on('click', "#close-sneak-preview", function() {
    $("#sneak-preview-btn").popover('hide');
  });
});

然后您可以修改按钮的框架或中心位置,如下所示:

// Screen Sizes
let screenWidth = UIScreen.mainScreen().bounds.width
let screenHeight = UIScreen.mainScreen().bounds.height

希望有所帮助