简体   繁体   中英

Sketch Plugin Develop : Is there an API for Sketch to unlock the size of MSBitmapLayer?

The unlock size button in Sketh App

I can click this button to unlock the size of a layer in Sketch App. And then I can change the width/height ratio of the image. But I want my Sketch plugin to do this job instead of using my hand to click the button. Is there an API for Sketch to unlock the size of MSBitmapLayer ?

I've tried " [layer setIsLocked:false] ", but it's not about the size lock.

Thank you very much.

The particular function you are looking for is setConstrainProportions()

Here is an example for you, It might help you in understanding it

function toggleConstrainProportions(context) {
  var doc = context.document
  var selection = context.selection

  // Toggles the currently selected item(s) 'Constrain Proportions'setting

  for (var i = 0; i < [selection count]; i++) {
    var s = [selection objectAtIndex: i]
    s.frame().setConstrainProportions(!s.constrainProportions())
  }
}

Hope this is helpful :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM