필터 지우기
필터 지우기

How do I replace a button with an icon in App Designer?

조회 수: 35 (최근 30일)
Niraj Desai
Niraj Desai 2023년 5월 2일
답변: Amit Dhakite 2023년 8월 11일
In App Designer, I place a button that users can press to get more information. But rather than the standard App Designer button (a rectangle with rounded corners), I would like to have a circle around a question mark. I can select Icon in the Button menu to insert a circled question mark PNG, but it is still encased in a rectangle. Is there a way of getting rid of the rectangle?
  댓글 수: 2
Jon
Jon 2023년 5월 2일
This has been asked before. Sounds like you can't change the shape of a button.
but as @Sean de Wolski suggest there
"You could use a uiimage instead. Then set it's ImageClickedFcn instead of ButtonPushedFcn callback"
Niraj Desai
Niraj Desai 2023년 5월 2일
Thanks for pointing that msg out. I'll try that.

댓글을 달려면 로그인하십시오.

답변 (1개)

Amit Dhakite
Amit Dhakite 2023년 8월 11일
Hi Niraj,
To use a circular image as a button, and to avoid the outer rectangular covering, you can follow the steps mentioned below inside the callback function associated with the click:
  1. Extract the x and y coordinates of the mouse click.
  2. Initialize 3 variables, “centerX” and “centerYrepresenting the center, and “radius” representing the radius of the circular image.
  3. Calculate the distance between the mouse clicked position and the center of the circle.
  4. If the distance is smaller than the radius of the circle, it means that the mouse is clicked inside the circle, and then you can implement the desired functionality there.
Please refer to the code shown below to implement the above mentioned functionality:
% Get the coordinates of the click
rpoint = get(app.UIFigure, 'CurrentPoint');
clickX = rpoint(1);
clickY = rpoint(2);
centerX = ; % x-coordinate of the circular image's center
centerY = ; % y-coordinate of the circular image's center
radius = ; % Radius of the circular image
distance = sqrt((clickX - centerX)^2 + (clickY - centerY)^2);
if distance <= radius
% Desired functionality
end
To know more about the axes properties such as “CurrentPoint, please refer to the following link:
Hope it helps!

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by